Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 24 additions & 40 deletions cxx/fbjni/detail/Exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,6 @@ namespace facebook {
namespace jni {

namespace {
class JRuntimeException : public JavaClass<JRuntimeException, JThrowable> {
public:
static auto constexpr kJavaDescriptor = "Ljava/lang/RuntimeException;";

static local_ref<JRuntimeException> create(const char* str) {
return newInstance(make_jstring(str));
}

static local_ref<JRuntimeException> create() {
return newInstance();
}
};

class JIOException : public JavaClass<JIOException, JThrowable> {
public:
static auto constexpr kJavaDescriptor = "Ljava/io/IOException;";

static local_ref<JIOException> create(const char* str) {
return newInstance(make_jstring(str));
}
};

class JOutOfMemoryError : public JavaClass<JOutOfMemoryError, JThrowable> {
public:
static auto constexpr kJavaDescriptor = "Ljava/lang/OutOfMemoryError;";

static local_ref<JOutOfMemoryError> create(const char* str) {
return newInstance(make_jstring(str));
}
};

class JArrayIndexOutOfBoundsException : public JavaClass<JArrayIndexOutOfBoundsException, JThrowable> {
public:
static auto constexpr kJavaDescriptor = "Ljava/lang/ArrayIndexOutOfBoundsException;";

static local_ref<JArrayIndexOutOfBoundsException> create(const char* str) {
return newInstance(make_jstring(str));
}
};

class JUnknownCppException : public JavaClass<JUnknownCppException, JThrowable> {
public:
static auto constexpr kJavaDescriptor = "Lcom/facebook/jni/UnknownCppException;";
Expand Down Expand Up @@ -186,6 +146,30 @@ void JThrowable::setStackTrace(alias_ref<JStackTrace> stack) {
return meth(self(), stack);
}

local_ref<JException> JException::create(const char *str) {
return newInstance(make_jstring(str));
}

local_ref<JException> JException::create() {
return newInstance();
}

local_ref<JRuntimeException> JRuntimeException::create(const char *str) {
return newInstance(make_jstring(str));
}
local_ref<JRuntimeException> JRuntimeException::create() {
return newInstance();
}
local_ref<JIOException> JIOException::create(const char *str) {
return newInstance(make_jstring(str));
}
local_ref<JOutOfMemoryError> JOutOfMemoryError::create(const char *str) {
return newInstance(make_jstring(str));
}
local_ref<JArrayIndexOutOfBoundsException> JArrayIndexOutOfBoundsException::create(const char *str) {
return newInstance(make_jstring(str));
}

auto JStackTraceElement::create(
const std::string& declaringClass, const std::string& methodName, const std::string& file, int line)
-> local_ref<javaobject> {
Expand Down
40 changes: 40 additions & 0 deletions cxx/fbjni/detail/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,46 @@ namespace jni {

class JThrowable;

class JException : public JavaClass<JException, JThrowable> {
public:
static constexpr const char* kJavaDescriptor = "Ljava/lang/Exception;";

static local_ref<JException> create(const char* str);

static local_ref<JException> create();
};

class JRuntimeException : public JavaClass<JRuntimeException, JException> {
public:
static auto constexpr kJavaDescriptor = "Ljava/lang/RuntimeException;";

static local_ref<JRuntimeException> create(const char* str);

static local_ref<JRuntimeException> create();
};

class JIOException : public JavaClass<JIOException, JException> {
public:
static auto constexpr kJavaDescriptor = "Ljava/io/IOException;";

static local_ref<JIOException> create(const char* str);
};

class JOutOfMemoryError : public JavaClass<JOutOfMemoryError, JThrowable> {
public:
static auto constexpr kJavaDescriptor = "Ljava/lang/OutOfMemoryError;";

static local_ref<JOutOfMemoryError> create(const char* str);
};

class JArrayIndexOutOfBoundsException
: public JavaClass<JArrayIndexOutOfBoundsException, JRuntimeException> {
public:
static auto constexpr kJavaDescriptor = "Ljava/lang/ArrayIndexOutOfBoundsException;";

static local_ref<JArrayIndexOutOfBoundsException> create(const char* str);
};

class JCppException : public JavaClass<JCppException, JThrowable> {
public:
static auto constexpr kJavaDescriptor = "Lcom/facebook/jni/CppException;";
Expand Down