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