@@ -143,6 +143,34 @@ void NativeScriptException::Init() {
143143 assert (NATIVESCRIPTEXCEPTION_GET_MESSAGE_METHOD_ID != nullptr );
144144}
145145
146+ std::string NativeScriptException::ToString () const {
147+ std::stringstream ss;
148+ if (!m_javaException.IsNull ()) {
149+ JEnv env;
150+ std::string message = GetExceptionMessage (env, m_javaException);
151+ std::string stackTrace = GetExceptionStackTrace (env, m_javaException);
152+ ss << " Java Exception: " << message << " \n " << stackTrace;
153+ } else if (m_javascriptException != nullptr ) {
154+ ss << " JavaScript Exception: " << m_message << " \n " << m_stackTrace;
155+ } else if (!m_message.empty ()) {
156+ ss << " Exception Message: " << m_message << " \n " << m_stackTrace;
157+ } else {
158+ ss << " No exception information available." ;
159+ }
160+ return ss.str ();
161+ }
162+
163+ std::string NativeScriptException::GetErrorMessage () const {
164+ if (!m_javaException.IsNull ()) {
165+ JEnv env;
166+ return GetExceptionMessage (env, m_javaException);
167+ } else if (m_javascriptException != nullptr ) {
168+ return m_message;
169+ } else {
170+ return m_message.empty () ? " No exception message available." : m_message;
171+ }
172+ }
173+
146174// ON V8 UNCAUGHT EXCEPTION
147175void NativeScriptException::OnUncaughtError (Local<Message> message, Local<Value> error) {
148176 string errorMessage = GetErrorMessage (message, error);
@@ -375,7 +403,7 @@ string NativeScriptException::GetErrorStackTrace(const Local<StackTrace>& stackT
375403 return ss.str ();
376404}
377405
378- string NativeScriptException::GetExceptionMessage (JEnv& env, jthrowable exception) {
406+ string NativeScriptException::GetExceptionMessage (JEnv& env, jthrowable exception) const {
379407 string errMsg;
380408 JniLocalRef msg (env.CallStaticObjectMethod (NATIVESCRIPTEXCEPTION_CLASS, NATIVESCRIPTEXCEPTION_GET_MESSAGE_METHOD_ID, exception));
381409
@@ -388,7 +416,7 @@ string NativeScriptException::GetExceptionMessage(JEnv& env, jthrowable exceptio
388416 return errMsg;
389417}
390418
391- string NativeScriptException::GetExceptionStackTrace (JEnv& env, jthrowable exception) {
419+ string NativeScriptException::GetExceptionStackTrace (JEnv& env, jthrowable exception) const {
392420 string errStackTrace;
393421 JniLocalRef msg (env.CallStaticObjectMethod (NATIVESCRIPTEXCEPTION_CLASS, NATIVESCRIPTEXCEPTION_GET_STACK_TRACE_AS_STRING_METHOD_ID, exception));
394422
0 commit comments