Cipherpack v1.2.0-dirty
A Cryprographic Stream Processor
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 <memory>
27#include <stdexcept>
28#include <vector>
29
30#include "helper_base.hpp"
31
32static std::string _unknown_exception_type_msg("Unknown exception type");
33
34void rethrow_and_raise_java_exception_impl(JNIEnv *env, const char* file, int line) {
35 // std::exception_ptr e = std::current_exception();
36 try {
37 // std::rethrow_exception(e);
38 throw; // re-throw current exception
39 } catch (const jau::OutOfMemoryError &e) {
40 jau::jni::raise_java_exception(env, e, file, line);
41 } catch (const jau::InternalError &e) {
42 jau::jni::raise_java_exception(env, e, file, line);
43 } catch (const jau::NullPointerException &e) {
44 jau::jni::raise_java_exception(env, e, file, line);
45 } catch (const jau::IllegalArgumentException &e) {
46 jau::jni::raise_java_exception(env, e, file, line);
47 } catch (const jau::IllegalStateException &e) {
48 jau::jni::raise_java_exception(env, e, file, line);
49 } catch (const jau::UnsupportedOperationException &e) {
50 jau::jni::raise_java_exception(env, e, file, line);
51 } catch (const jau::IndexOutOfBoundsException &e) {
52 jau::jni::raise_java_exception(env, e, file, line);
53 } catch (const jau::RuntimeException &e) {
54 jau::jni::raise_java_exception(env, e, file, line);
55 } catch (const std::bad_alloc &e) {
56 jau::jni::raise_java_exception(env, e, file, line);
57 } catch (const std::runtime_error &e) {
58 jau::jni::raise_java_exception(env, e, file, line);
59 } catch (const std::invalid_argument &e) {
60 jau::jni::raise_java_exception(env, e, file, line);
61 } catch (const std::exception &e) {
62 jau::jni::raise_java_exception(env, e, file, line);
63 } catch (const std::string &msg) {
64 jau::jni::print_native_caught_exception_fwd2java(msg, file, line);
65 env->ThrowNew(env->FindClass("java/lang/Error"), msg.c_str());
66 } catch (const char *msg) {
67 jau::jni::print_native_caught_exception_fwd2java(msg, file, line);
68 env->ThrowNew(env->FindClass("java/lang/Error"), msg);
69 } catch (...) {
70 jau::jni::print_native_caught_exception_fwd2java(_unknown_exception_type_msg, file, line);
71 env->ThrowNew(env->FindClass("java/lang/Error"), _unknown_exception_type_msg.c_str());
72 }
73}
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.
Definition: helper_base.cxx:34