Results 1 to 3 of 3

Thread: Automatic display of Exception\Error

  1. #1
    Ext User dommellenny's Avatar
    Join Date
    Oct 2009
    Location
    Geel, Belgium
    Posts
    23

    Default Automatic display of Exception\Error

    Hi,
    i'm creating a very extended project with some basic functionality like a form, editorgrid, etc.
    i found a good way of displaying errormessages by creating a class Message.js with the following code:
    Code:
    ErrorHandler = function() {
    return {
    init: function() {
    window.onerror = !window.onerror ? ErrorHandler.handleError : window.onerror.createSequence(ErrorHandler.handleError);
    },
    getFormattedMessage: function(args) {
    var lines = ["The following error has occured:"];
    if (args[0] instanceof Error) { // Error object thrown in try...catch
    var err = args[0];
    lines[lines.length] = "Message: (" + err.name + ") " + err.message;
    lines[lines.length] = "Error number: " + (err.number & 0xFFFF); //Apply binary arithmetic for IE number, firefox returns message string in element array element 0
    lines[lines.length] = "Description: " + err.description;
    } elseif ((args.length == 3) && (typeof (args[2]) == "number")) { // Check the signature for a match with an unhandled exception
    lines[lines.length] = "Message: " + args[0];
    lines[lines.length] = "URL: " + args[1];
    lines[lines.length] = "Line Number: " + args[2];
    } else {
    lines = ["An unknown error has occured."]; // purposely rebuild lines
    lines[lines.length] = "The following information may be useful:"
    for (var x = 0; x < args.length; x++) {
    lines[lines.length] = Ext.encode(args[x]);
    }
    }
    return lines.join("\n");
    },
    displayError: function(args) {
    // purposely creating a new window for each exception (to handle concurrent exceptions)
    var errWindow = new Ext.Window({
    autoScroll: true,
    bodyStyle: { padding: 5 },
    height: 150,
    html: this.getFormattedMessage(args).replace(/\n/g, "<br />").replace(/\t/g, " &nbsp; &nbsp;"),
    modal: true,
    title: "An error has occurred",
    width: 400
    });
    errWindow.show();
    },
    logToServer: function(args) {
    Ext.Ajax.request({
    params: {
    a: "PostErrorInfo",
    error: Ext.encode(args)
    },
    url: "Default.aspx"
    });
    },
    handleError: function() {
    var args = [];
    for (var x = 0; x < arguments.length; x++) {
    args[x] = arguments[x];
    }
    try {
    this.displayError(args);
    this.logToServer(args);
    } catch (e) {
    // if the errorHandler is broken, let the user see the browser's error handler
    returnfalse;
    }
    returntrue;
    }
    };
    } ();
    // the following line ensures that the handleError method always executes in the scope of ErrorHandler
    ErrorHandler.handleError = ErrorHandler.handleError.createDelegate(ErrorHandler);
    ErrorHandler.init();
    
    I can now easily display an error with one line of code by calling
    Code:
    
    ErrorHandler.handleError(data.errorMessage);
    
    but since i am creating a very extended application even this is a lot to type over and over again (+/- 1000 times)....
    now i've heard there's a way of letting all the errors show automatically
    is there anyone who has already done this? or know how to do it?
    i cannot find it on the net so i'm throwing all my hopes to our nice forum....

  2. #2
    Ext User dommellenny's Avatar
    Join Date
    Oct 2009
    Location
    Geel, Belgium
    Posts
    23

    Default

    anybody who made this?
    or who can set me on my way by telling me where the errors are being put into a variable???

  3. #3
    Ext User dommellenny's Avatar
    Join Date
    Oct 2009
    Location
    Geel, Belgium
    Posts
    23

    Default

    no tips or any direction where i should be looking?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •