Unverified Commit 186bc0d7 authored by Igor Demin's avatar Igor Demin Committed by GitHub

Throw a java exception on native crash by default (Windows, Linux) (#588)

This was enabled in Toolbox, and it seems work without issues.

When we throw RenderException, we fallback to the next render API.
parent b966862f
......@@ -4,6 +4,6 @@
#include <windows.h>
#include <stdio.h>
void logJavaException(JNIEnv *env, const char * function, DWORD sehCode);
void throwJavaException(JNIEnv *env, const char * function, DWORD sehCode);
#endif
\ No newline at end of file
......@@ -61,7 +61,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
}
......@@ -88,7 +88,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
}
......
......@@ -25,7 +25,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
}
}
......
......@@ -321,7 +321,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
}
......@@ -341,7 +341,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
}
......@@ -396,7 +396,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
}
......@@ -413,7 +413,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
}
......@@ -441,7 +441,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
}
......
......@@ -3,20 +3,6 @@
#include "exceptions_handler.h"
#include "../common/interop.hh"
bool isHandleException(JNIEnv *env)
{
jstring propertyName = env->NewStringUTF("skiko.win.exception.handler.enabled");
jstring propertyString = (jstring)env->CallStaticObjectMethod(java::lang::System::cls, java::lang::System::getProperty, propertyName);
if (propertyString == 0)
{
return false;
}
const char *property = env->GetStringUTFChars(propertyString, 0);
bool result = !strncmp(property, "true", 4);
env->ReleaseStringUTFChars(propertyString, property);
return result;
}
const char *getDescription(DWORD code)
{
switch (code)
......@@ -66,17 +52,14 @@ const char *getDescription(DWORD code)
}
}
void logJavaException(JNIEnv *env, const char *function, DWORD sehCode)
void throwJavaException(JNIEnv *env, const char *function, DWORD sehCode)
{
if (isHandleException(env))
{
char buffer[200];
int result = snprintf(
buffer, sizeof(buffer) - 1, "Native exception in [%s]:\nSEH description: %s\n", function, getDescription(sehCode));
static jclass logClass = (jclass) env->NewGlobalRef(env->FindClass("org/jetbrains/skiko/RenderExceptionsHandler"));
static jmethodID logMethod = env->GetStaticMethodID(logClass, "throwException", "(Ljava/lang/String;)V");
env->CallStaticVoidMethod(logClass, logMethod, env->NewStringUTF(buffer));
}
char buffer[200];
int result = snprintf(
buffer, sizeof(buffer) - 1, "Native exception in [%s]:\nSEH description: %s\n", function, getDescription(sehCode));
static jclass logClass = (jclass) env->NewGlobalRef(env->FindClass("org/jetbrains/skiko/RenderExceptionsHandler"));
static jmethodID logMethod = env->GetStaticMethodID(logClass, "throwException", "(Ljava/lang/String;)V");
env->CallStaticVoidMethod(logClass, logMethod, env->NewStringUTF(buffer));
}
#endif
\ No newline at end of file
......@@ -34,7 +34,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
return (jlong) 0;
}
......@@ -54,7 +54,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
}
......@@ -67,7 +67,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
}
......@@ -93,7 +93,7 @@ extern "C"
}
__except(EXCEPTION_EXECUTE_HANDLER) {
auto code = GetExceptionCode();
logJavaException(env, __FUNCTION__, code);
throwJavaException(env, __FUNCTION__, code);
}
return (jlong) 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment