iOS JavascriptCore exception detailed stacktrace info
Asked Answered
I

2

7

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.

context.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.

Immortalize answered 14/12, 2015 at 17:55 Comment(2)
are these keys like stack, line or column documented anywhere? How did you figure out those existed?Stiffnecked
I don't remember if this is documented anywhere. I don't remember how I figured it out either. But since it is a JSValue, then it can be a JS object or any other JS type, maybe I just printed it out to see what it contains.Immortalize
I
1

Looks like it does show more information in the stack. Here is one of the log information I got:

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
Immortalize answered 7/1, 2016 at 23:34 Comment(3)
How did you do it?Isolative
The above code mentioned in the question is what I did. It was not showing much information in the question is because the method causing issue is at the global level, so it does not have much stack anyway. In the answer, the methods is deep in the stack, so it shows more information now. So my code is actually working.Immortalize
This is exciting! It is sooo much easier to find and fix problems with a bona fide STStoffel
C
0

Long ago, @igrek asked where the keys in value come from. They're part of the Error object that was thrown by the JavaScript engine, and that now appears as value in the native error handler callback. What exactly Error includes depends on the implementation, but typically includes message, fileName, and lineNumber. It appears that stack is also supported. More details on the MDN page for Error .

Caponize answered 30/5, 2019 at 23:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.