@@ -72,6 +72,26 @@ void SIG_handler(int sigNumber) {
7272 throw NativeScriptException (msg.str ());
7373}
7474
75+ void LogAndAbortUncaught () {
76+ try {
77+ throw ; // rethrow the current unknown
78+ } catch (const tns::NativeScriptException& e) {
79+ // We only have message/stack; no safe ReThrowToJava here.
80+ __android_log_print (ANDROID_LOG_FATAL, " TNS.Native" ,
81+ " Uncaught NativeScriptException: %s" ,
82+ e.ToString ().c_str ());
83+ } catch (const std::exception& e) {
84+ __android_log_print (ANDROID_LOG_FATAL, " TNS.Native" ,
85+ " Uncaught std::exception: %s" , e.what ());
86+ } catch (...) {
87+ __android_log_print (ANDROID_LOG_FATAL, " TNS.Native" ,
88+ " Uncaught unknown native exception" );
89+ }
90+
91+ // Preserve default abort behavior so crashes are visible to tooling
92+ std::_Exit (EXIT_FAILURE);
93+ }
94+
7595void Runtime::Init (JavaVM* vm, void * reserved) {
7696 __android_log_print (ANDROID_LOG_INFO, " TNS.Runtime" ,
7797 " NativeScript Runtime Version %s, commit %s" ,
@@ -92,6 +112,8 @@ void Runtime::Init(JavaVM* vm, void* reserved) {
92112 sigaction (SIGABRT, &action, NULL );
93113 sigaction (SIGSEGV, &action, NULL );
94114 }
115+ // Set terminate handler for uncaught exceptions
116+ std::set_terminate (LogAndAbortUncaught);
95117}
96118
97119int Runtime::GetAndroidVersion () {
0 commit comments