Loading ...
Sorry, an error occurred while loading the content.

Exception management problem

Expand Messages
  • Pablo Ruggia
    Hi ! I m having a strange problem, every time an exception is thrown inside an event fired by YUI, like a button click, the exception is no logged anywhere
    Message 1 of 2 , Feb 1, 2008
    View Source
    • 0 Attachment
      Hi !
      I'm having a strange problem, every time an exception is thrown inside an event fired by YUI, like a button click, the exception is no logged anywhere (not in firebug, not in yahoo loader, no alert window, etc.). It just stops executing.
      Other events not fired by yui are working fine.
      Any idea what's happening ?
      Thanks !
    • Joel Hillacre
      ... It has been little over 2 weeks since you asked your question but I m hoping i can answer your question. In YAHOO.util.CustomEvent.fire, there is a
      Message 2 of 2 , Feb 15, 2008
      View Source
      • 0 Attachment
        > Exception management problem
        > Posted by: "Pablo Ruggia" pruggia@ pruggia2
        > Fri Feb 1, 2008 6:06 am (PST)
        > Hi !
        > I'm having a strange problem, every time an exception is thrown inside an
        > event fired by YUI, like a button click, the exception is no logged
        > anywhere
        > (not in firebug, not in yahoo loader, no alert window, etc.). It just
        > stops
        > executing.
        > Other events not fired by yui are working fine.
        > Any idea what's happening ?
        > Thanks !
        It has been little over 2 weeks since you asked your question but I'm
        hoping i can answer your question.

        In YAHOO.util.CustomEvent.fire, there is a try-catch wrapped around the
        function that you subscribed which catches exceptions in your code. To
        get these exceptions, you should catch and handle these exceptions in
        your subscribed function. You could also check
        myInstance.someEvent.lastError to see what was the last error thrown for
        a certain For debugging purposes, you can wrap your subscribed
        function like this...

        function myClickHandler(e) {
        setTimeout(function () {
        ...your code here...
        }, 1);
        }

        This will remove your code outside of current stack, and outside the try
        catch block. Exceptions will go to your firebug/firefox consoles.

        For my current project, we wanted exceptions emailed to us if off site
        clients run into issues. To accomplish this, we monkey patched
        YAHOO.util.CustomEvent.fire with our own version of the function, which
        looks something like this.

        // YUI CustomEvent sucks up our errors :(
        // TODO: If we update YUI, update this.
        YAHOO.example.myApp.customEventFirePatch = function() {
        var len=this.subscribers.length;
        if (!len && this.silent) {
        return true;
        }

        var args=[], ret=true, i, rebuild=false;

        for (i=0; i<arguments.length; ++i) {
        args.push(arguments[i]);
        }

        if (!this.silent) {
        }

        for (i=0; i<len; ++i) {
        var s = this.subscribers[i];
        if (!s) {
        rebuild=true;
        } else {
        if (!this.silent) {
        }

        var scope = s.getScope(this.scope);

        if (this.signature == YAHOO.util.CustomEvent.FLAT) {
        var param = null;
        if (args.length > 0) {
        param = args[0];
        }

        try {
        ret = s.fn.call(scope, param, s.obj);
        } catch(e) {
        this.lastError = e;
        AZCAT.utils.errorCatcher(e);
        }
        } else {
        try {
        ret = s.fn.call(scope, this.type, args, s.obj);
        } catch(ex) {
        this.lastError = ex;
        YAHOO.example.myApp.errorCatcher(ex);
        }
        }
        if (false === ret) {
        if (!this.silent) {
        }

        //break;
        return false;
        }
        }
        }

        if (rebuild) {
        var newlist=[],subs=this.subscribers;
        for (i=0,len=subs.length; i<len; i=i+1) {
        newlist.push(subs[i]);
        }

        this.subscribers=newlist;
        }

        return true;
        };

        if (YAHOO.util.CustomEvent.prototype) {
        YAHOO.util.CustomEvent.prototype.fire = YAHOO.example.myApp.customEventFirePatch;
        }


        It would be great, if in the future, there was some way to pass a
        function to the subscribe method which would allow us to handle
        exceptions that are thrown inside our function and not caught.
        Something like myMenu.someEvent.subscribe(someEventHandler, this, true,
        errorHandler); or myMenu.someEvent.subscribe({fn:someEventHandler,
        obj:this, override:true, errorfn:errorHandler});

        --
        Joel Hillacre - Developer
        mailto:joel@...
        phone: 780.413.6397 ext. 232

        Emergence by Design
        http://www.emergence.com
        mailto:info@...
        toll free: 1.866.860.2666
      Your message has been successfully submitted and would be delivered to recipients shortly.