Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11653] Android: Add script errors/stack trace to TiExceptionHandler data

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-01-29T01:23:40.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.1.0, 2013 Sprint 03 Core, 2013 Sprint 03
ComponentsAndroid
Labelsn/a
ReporterMax Stepanov
AssigneeHieu Pham
Created2012-11-02T17:33:15.000+0000
Updated2017-03-16T21:43:35.000+0000

Description

JavaScript:
// Without try catch:
var err = new Error("My Awesome Caught Error!");
API.logHandledException(err);

try {
var err = new Error("My Awesome Caught Error!");
throw err

} catch (err){
API.logHandledException(err);
}
Objective-C:
-(void)logHandledException:(id)args
{
    TiLogMessage([NSString stringWithFormat:@"class type?: %@", [[args objectAtIndex:0] class]]); // This returns as NSDictionary, is this expected?

//    TiScriptError *exception = [TiScriptError initWithDictionary:[args objectAtIndex:0]]; // This selector doesn't exist?
    TiScriptError *exception = (TiScriptError *)args; // Returns an array, not a single object. In other methods, they returned the objects rather than an array of parameters.

[API logHandledException:[self convertScriptErrorToNative:exception]];
}
Testing steps: 1. Download CritterModule, and build it with a Titanium Mobile project. 2. Run this code (app.js):
var CritterModule = require('com.crittermodule');

var win = Ti.UI.createWindow({fullscreen: true, backgroundColor: 'white'});

var stackLabel = Ti.UI.createLabel({
	left: "10%",
	top: "20%",
	color: 'red'
	
});
var lineNumberLabel = Ti.UI.createLabel({
	left: "10%",
	top: "50%",
	color: 'red'
	
});
var messageLabel = Ti.UI.createLabel({
	left: "10%",
	top: "70%",
	color: 'red'
	
});
var fileNameLabel = Ti.UI.createLabel({
	left: "10%",
	top: "85%",
	color: 'red'
	
});

var errorButton = Ti.UI.createButton({
	top: 0,
	title: "Throw error"
});

var err = new Error("uh oh!");
errorButton.addEventListener("click", function(e){
	try {
		throw err;
	} catch(e) {
		stackLabel.text = CritterModule.printErrorStack(e);
		lineNumberLabel.text = "Line number: " + CritterModule.printErrorLineNumber(e);
		messageLabel.text = "Error Message: " + CritterModule.printErrorMessage(e);
		fileNameLabel.text = "File name: " + CritterModule.printErrorFileName(e);
}

});




win.add(stackLabel);
win.add(lineNumberLabel);
win.add(messageLabel);
win.add(fileNameLabel);
win.add(errorButton);
win.open();
3. Click on "Throw error" button. You should see the stack trace, line number, error message and file name.

Attachments

FileDateSize
com.crittermodule.zip2013-01-15T16:52:21.000+000049846
CritterModule.zip2013-01-14T13:39:14.000+000063063

Comments

  1. Allen Yeung 2012-11-02

    In Android, we already have an API to do this: KrollRuntime.dispatchException()
  2. Ingo Muschenetz 2012-11-28

    This evidently still needs to be done.
  3. Allen Yeung 2013-01-09

    https://github.com/appcelerator/titanium_mobile/pull/3685
  4. Lee Morris 2017-03-16

    Closing ticket as the issue has been fixed.

JSON Source