Javascript: Exception Details

Skip Navigation LinksIrocon > Blog > 2008 > May, 2008 > May 08, 2008 > Javascript: Exception Details

Javascript: Exception Details

Exceptions do occur in any programming language, and knowing the type and details of the exception can be very crucial in debugging and determining a solution to the cause. I recently ran  into a problem with one of my javascript functions and could not figure out why it was occurring. Little did I know that Javascript also provides exception information in the try, catch block. Here goes:

 

try {
  myObject.myFunction(arg)
}
catch (e) {
  if (e.description.indexOf('access') !=-1) myObject.otherFunction(arg)
  else alert(e.description)
}

Last Updated:Thursday, September 02, 2010By:alfero#

Would you like to comment?

Sign in with your OpenID. If you do not know what OpenID is, find out.