Stack trace on exception

Stack trace on exception
0

Hey is there anyway to output the stack trace when an exception occurs? Right now it just shows the line number of the file and the reason why js crashed. It’d be really useful to also get a stack trace.

try this (not tested).

var e = new Error('dummy');
var stack = e.stack;
cc.log(stack);

Any js code that works on Firefox will work for Cocos2D-js (this includes the native portion as well)

That definitely works in JS but I was hoping for a catch all where I didn’t have to manually add the call stack code after the fact. I was poking around in the ScriptingCore::reportError function to try to see if I could patch anything through but haven’t been able to figure out anything useful.

I’m trying to get the same functionality that is available in lua where you can overload an error function call like this

function __G__TRACKBACK__(msg)
  cclog("----------------------------------------");
  cclog("LUA ERROR: " .. tostring(msg) .. "\n");
  cclog(debug.traceback());
  cclog("----------------------------------------");
end;

This wont work for js. You will have best luck running the runtime on your favorite editor (vs2012, xcode or eclipse) in debug mode and sync your files with remote debugger from cocos IDE. then you will debug both the js and native code!

Hmmm, is that just a limitation of spidermonkey? It seems smart enough to give me back a file and line number and going through the cocos IDE there is a call stack available. I’m trying to hook something up so testers can send something a little more useful and they may not have access to the code base or want to go through the process of setting up the environment.

Is not the spidermokey limitation, but how the error is handled in the libJSBinding calling JS_ReportError with little info in all places.

JS_ReportError is a function of the spidermokey api so to mod it you will need to recompile, this can be a lot of pain or maybe not. Try replace and refactor JS_ReportError with a custom function to return more info.

@El_Jorge @pyiap https://github.com/cocos2d/cocos2d-x/pull/20168
This PR is merged now. Please check whether it helps.