Skip to content

Commit

Permalink
修改错误输出
Browse files Browse the repository at this point in the history
  • Loading branch information
scgm0 committed Apr 23, 2024
1 parent 33e4bdd commit 1e66b69
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions unity/native_src/Inc/V8Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ class FV8Utils
else
{
v8::Local<v8::Context> Context(Isolate->GetCurrentContext());

// 输出 (filename):(line number): (message).
std::ostringstream stm;
v8::String::Utf8Value FileName(Isolate, Message->GetScriptResourceName());
int LineNum = Message->GetLineNumber(Context).FromJust();
const char * StrFileName = *FileName;
stm << (StrFileName == nullptr ? "unknow file" : StrFileName) << ":" << LineNum << ": " << ExceptionStr;

stm << std::endl;

// 输出调用栈信息
v8::MaybeLocal<v8::Value> MaybeStackTrace = v8::TryCatch::StackTrace(Context, ExceptionValue);
if (!MaybeStackTrace.IsEmpty())
if (ExceptionStr.rfind("SyntaxError:", 0) == 0)
{
v8::String::Utf8Value FileName(Isolate, Message->GetScriptResourceName());
int LineNum = Message->GetLineNumber(Context).FromJust();
int ColumnNum = Message->GetStartColumn(Context).FromJust();
const char* StrFileName = *FileName;
stm << ExceptionStr << std::endl << " at " << (StrFileName == nullptr ? "unknow file" : StrFileName) << ":" << LineNum << ":" << ColumnNum;
}
else if (!MaybeStackTrace.IsEmpty())
{
v8::String::Utf8Value StackTraceVal(Isolate, MaybeStackTrace.ToLocalChecked());
stm << std::endl << *StackTraceVal;
stm << *StackTraceVal;
}
return stm.str();
}
Expand Down

0 comments on commit 1e66b69

Please sign in to comment.