-
-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathNativeScriptException.h
More file actions
110 lines (88 loc) · 3.72 KB
/
NativeScriptException.h
File metadata and controls
110 lines (88 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef NATIVESCRIPTEXCEPTION_H_
#define NATIVESCRIPTEXCEPTION_H_
#include "v8.h"
#include "JEnv.h"
#include "JniLocalRef.h"
#include "ObjectManager.h"
#include "include/v8.h"
namespace tns {
class NativeScriptException {
public:
/*
* Generates a NativeScriptException with java error from environment
*/
NativeScriptException(JEnv& env);
/*
* Generates a NativeScriptException with given message
*/
NativeScriptException(const std::string& message);
/*
* Generates a NativeScriptException with given message and stackTrace
*/
NativeScriptException(const std::string& message, const std::string& stackTrace);
/*
* Generates a NativeScriptException with javascript error from TryCatch and a prepend message if any
*/
NativeScriptException(v8::TryCatch& tc, const std::string& message = "");
void ReThrowToV8();
void ReThrowToJava();
std::string ToString() const;
std::string GetErrorMessage() const;
static void Init();
/*
* This handler is attached to v8 to handle uncaught javascript exceptions.
*/
static void OnUncaughtError(v8::Local<v8::Message> message, v8::Local<v8::Value> error);
/*
* Calls the global "__onUncaughtError" or "__onDiscardedError" if such is provided
*/
static void CallJsFuncWithErr(v8::Local<v8::Value> errObj, jboolean isDiscarded);
private:
/*
* Try to get native exception or NativeScriptException from js object
*/
JniLocalRef TryGetJavaThrowableObject(JEnv& env, const v8::Local<v8::Object>& jsObj);
/*
* Gets java exception message from jthrowable
*/
std::string GetExceptionMessage(JEnv& env, jthrowable exception) const;
/*
* Gets java exception stack trace from jthrowable
*/
std::string GetExceptionStackTrace(JEnv& env, jthrowable exception) const;
/*
* Gets the member m_javaException, wraps it and creates a javascript error object from it
*/
v8::Local<v8::Value> WrapJavaToJsException();
/*
* Gets all the information from a java exception and puts it in a javascript errror object
*/
v8::Local<v8::Value> GetJavaExceptionFromEnv(const JniLocalRef& exc, JEnv& env);
/*
* Gets all the information from a js message and an js error object and puts it in a string
*/
static std::string GetErrorMessage(const v8::Local<v8::Message>& message, v8::Local<v8::Value>& error, const std::string& prependMessage = "");
/*
* Generates string stack trace from js StackTrace
*/
static std::string GetErrorStackTrace(const v8::Local<v8::StackTrace>& stackTrace);
/*
* Adds a prepend message to the normal message process
*/
std::string GetFullMessage(const v8::TryCatch& tc, const std::string& jsExceptionMessage);
v8::Persistent<v8::Value>* m_javascriptException;
JniLocalRef m_javaException;
std::string m_message;
std::string m_stackTrace;
std::string m_fullMessage;
static jclass RUNTIME_CLASS;
static jclass THROWABLE_CLASS;
static jclass NATIVESCRIPTEXCEPTION_CLASS;
static jmethodID NATIVESCRIPTEXCEPTION_JSVALUE_CTOR_ID;
static jmethodID NATIVESCRIPTEXCEPTION_THROWABLE_CTOR_ID;
static jmethodID NATIVESCRIPTEXCEPTION_GET_MESSAGE_METHOD_ID;
static jmethodID NATIVESCRIPTEXCEPTION_GET_STACK_TRACE_AS_STRING_METHOD_ID;
static void PrintErrorMessage(const std::string& errorMessage);
};
}
#endif /* NATIVESCRIPTEXCEPTION_H_ */