Cipherpack v1.3.0-3-ga29431a
A Cryprographic Stream Processor
Loading...
Searching...
No Matches
helper_base.cxx
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2022 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#include <jni.h>
26#include <jau/basic_types.hpp>
27#include <memory>
28#include <stdexcept>
29#include <vector>
30
31#include "helper_base.hpp"
32
33static std::string _unknown_exception_type_msg("Unknown exception type");
34
35void rethrow_and_raise_java_exception_impl(JNIEnv *env, const char* file, int line) {
36 // std::exception_ptr e = std::current_exception();
37 try {
38 // std::rethrow_exception(e);
39 throw; // re-throw current exception
40 } catch (const jau::OutOfMemoryError &e) {
41 jau::jni::raise_java_exception(env, e, file, line);
42 } catch (const jau::InternalError &e) {
43 jau::jni::raise_java_exception(env, e, file, line);
44 } catch (const jau::NullPointerException &e) {
45 jau::jni::raise_java_exception(env, e, file, line);
46 } catch (const jau::IllegalArgumentError &e) {
47 jau::jni::raise_java_exception(env, e, file, line);
48 } catch (const jau::IllegalStateError &e) {
49 jau::jni::raise_java_exception(env, e, file, line);
50 } catch (const jau::UnsupportedOperationException &e) {
51 jau::jni::raise_java_exception(env, e, file, line);
52 } catch (const jau::IndexOutOfBoundsError &e) {
53 jau::jni::raise_java_exception(env, e, file, line);
54 } catch (const jau::RuntimeExceptionBase &e) {
55 jau::jni::raise_java_exception(env, e, file, line);
56 } catch (const jau::ExceptionBase &e) {
57 jau::jni::raise_java_exception(env, e, file, line);
58 } catch (const std::bad_alloc &e) {
59 jau::jni::raise_java_exception(env, e, file, line);
60 } catch (const std::runtime_error &e) {
61 jau::jni::raise_java_exception(env, e, file, line);
62 } catch (const std::invalid_argument &e) {
63 jau::jni::raise_java_exception(env, e, file, line);
64 } catch (const std::exception &e) {
65 jau::jni::raise_java_exception(env, e, file, line);
66 } catch (const std::string &msg) {
67 jau::jni::print_native_caught_exception_fwd2java(msg, file, line);
68 env->ThrowNew(env->FindClass("java/lang/Error"), msg.c_str());
69 } catch (const char *msg) {
70 jau::jni::print_native_caught_exception_fwd2java(msg, file, line);
71 env->ThrowNew(env->FindClass("java/lang/Error"), msg);
72 } catch (...) {
73 jau::jni::print_native_caught_exception_fwd2java(_unknown_exception_type_msg, file, line);
74 env->ThrowNew(env->FindClass("java/lang/Error"), _unknown_exception_type_msg.c_str());
75 }
76}
static std::string _unknown_exception_type_msg("Unknown exception type")
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2022 Gothel Software e.K.
void rethrow_and_raise_java_exception_impl(JNIEnv *env, const char *file, int line)
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2022 Gothel Software e.K.