JScript and Exceptions

So, one of the disadvantages of JScripts is the lack of visibility when it comes to exceptions – it can make troubleshooting frustratingly difficult. It is especially challenging when you are so used to the richness of the .Net exceptions.

I was recently working on a project where I got the wonderful Examine the InnerException for details, the only problem being that there is no InnerException property or field on the JScript exception.

If we do a GetType() on our exception object we see that it is an ErrorObject class
http://msdn.microsoft.com/en-us/library/microsoft.jscript.errorobject(v=vs.110).aspx

and not inherited from System.Exception.

After some investigation, I came across this post:
http://blogs.msdn.com/b/heaths/archive/2005/09/20/471908.aspx
which nicely explains what happens and how to extract the .Net exception to get more detail.

In a nutshell, we test to ensure that our exception object is an ErrorObject using the instanceof command and then we use the static operator Explicit from the ErrorObject to convert it to an Exception.

This entry was posted in Development, M3 / MoveX, Misc. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s