[TIMOB-11653] Android: Add script errors/stack trace to TiExceptionHandler data
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-01-29T01:23:40.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 3.1.0, 2013 Sprint 03 Core, 2013 Sprint 03 |
Components | Android |
Labels | n/a |
Reporter | Max Stepanov |
Assignee | Hieu Pham |
Created | 2012-11-02T17:33:15.000+0000 |
Updated | 2017-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
File | Date | Size |
---|---|---|
com.crittermodule.zip | 2013-01-15T16:52:21.000+0000 | 49846 |
CritterModule.zip | 2013-01-14T13:39:14.000+0000 | 63063 |
In Android, we already have an API to do this: KrollRuntime.dispatchException()
This evidently still needs to be done.
https://github.com/appcelerator/titanium_mobile/pull/3685
Closing ticket as the issue has been fixed.