error handling - Catching "NullPointerExceptions" in JavaScript -
i'm writing quite bit of code in prototype.js returns null if dom-id wasn't found.
$("someid").show();
if someid
doesn't exist, method called on null, halts entire program, in effect disabling js effects after error. check null before executing such statement, getting tiring.
i catch exception i'm not sure 1 is. mdc lists following ecma script error types, on first glance none of them seem want:
* error * evalerror * rangeerror * referenceerror * syntaxerror * typeerror * urierror * domexception * eventexception * rangeexception
also, browsers have unified way of dealing method call on null?
i don't believe there's unity found. chrome throws typeerror, ie throws error, have catch , make severe assumptions. better check null first.
var element = $('someid'); if (element) { element.show(); // whatever else... }
if element.show()
thing need for, can written lot shorter, in cases appropriate.
Comments
Post a Comment