Wednesday, August 17th, 2005

Debugging Prototype and catch(e) {} evilness :)

Category: Editorial, Prototype

I was helping someone debug some Prototype code. The problem was on a small demo thang, nothing was happening.

After starting the debugging it was instantly obvious that the XHR request was not even being made.

Then I looked at the Ajax code in Prototype and found:

Ajax.Request.prototype = (new Ajax.Base()).extend({
 ...
 request: function(url) {
  ...
  try {
   ... do transport stuff ...
  } catch (e) {  
  }
},...

After tweaking to add:

    } catch (e) {
    	alert(e);
    }

we quickly saw that there wasn’t permission to call xhr.open. This was due to the client loading a local html file and calling a service… and you need permission to do this.

Having catch(e) {} can produce hard to find bugs though… so watch out :)

Posted by Dion Almaer at 1:49 am
2 Comments

+++--
3.2 rating from 6 votes

2 Comments »

Comments feed

Catching the exception is not dangerous by itself and is good practice though.
The dangerous thing producing hard to debug code is doing nothing on catches (no bubbling exceptions, no traces, no logs), akin to old VB’s “On Error Resume Next”‘s trademark of crappy programmers

Comment by Masklinn — August 17, 2005

I’ve posted a workaround for catching these kinds of errors at my blog:

“AJAX: How to Catch Evil Errors with OnError” – http://codinginparadise.org/weblog/2005/08/ajax-how-to-catch-evil-errors-with.html

Comment by Brad Neuberg — August 22, 2005

Leave a comment

You must be logged in to post a comment.