Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-11653

Android: Add script errors/stack trace to TiExceptionHandler data

    Details

      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

          Issue Links

            Activity

              People

              • Assignee:
                hpham Hieu Pham
                Reporter:
                mstepanov Max Stepanov
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-14858
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration