iOS JavascriptCore exception detailed stacktrace info

时间:2015-12-14 17:55:35

标签: swift javascriptcore

It seems the exception stacktrace in iOS only contains the method name or there is a bug. Below is my code of handling exceptions in JSContext.

ontext.exceptionHandler = { (ctx: JSContext!, value: JSValue!) in
    // type of String
    let stacktrace = value.objectForKeyedSubscript("stack").toString()
    // type of Number
    let lineNumber = value.objectForKeyedSubscript("line")
    // type of Number
    let column = value.objectForKeyedSubscript("column")
    let moreInfo = "in method \(stacktrace)Line number in file: \(lineNumber), column: \(column)"
    Logger.error("JS ERROR: \(value) \(moreInfo)")
}

And I got logs like below

ERROR : JSContextRenderer.swift:308 : setupContext : JS ERROR: Error in method clearBackground
Line number in file: 162, column: 12"

Note there is a new line right after the "clearBackground" name, I think there probably more information there.

Can anybody having similar experience confirm? Any help is appreciated. Thanks.

2 个答案:

答案 0 :(得分:1)

看起来确实在stack中显示了更多信息。这是我得到的日志信息之一:

JS ERROR: TypeError: undefined is not a function (evaluating 'msg.__assert__()') in method assert
syncShots
updateSync
initSync
setState
onLogicStateChanged
onLogicStateChanged
[native code]
updateMove
sendMove
shoot
onTouchUp
[native code]
_handleEvent
_dispatchEvent
. Line number in file: 183, column: 20

答案 1 :(得分:0)

很久以前,@ igrek询问value中的密钥来自何处。它们是JavaScript引擎抛出的Error对象的一部分,现在在本机错误处理程序回调中显示为valueError确切包含的内容取决于实现,但通常包括messagefileNamelineNumber。似乎也支持stack。有关MDN page for Error的更多详细信息。