If there is one thing that can drive me insane is the way in which Javascript handles errors.
The way Javascript does this is dependant, to a degree, on the browser implementation, but the worst offender for me occurs in Adobe Air ( and quite likely some other browsers too).
Let’s first introduce the scenario. Imagine a large framework built up with several Javascript ‘classes’, with multiple functions in each class.
Now, creating an instance of the class, and using the object, one of the functions generates an error when you call the function. Let’s assume the reason for the error was intermittent, caused by an improperly set parameter. What I mean is, that the function in question should not consistently fail, but only failed in that one instance.
The problem comes in that Javascript then decides that, since the function failed, then there is a problem with it, and consequently refuses to execute that function again after it has failed.
In a real world example, I had a function that starts a file download. It would work fine, until it crashed trying to download a file that does not exist, and after that, every call to that function would fail until I restarted the application. It is a problem that can cause some severe debugging headaches unless you are aware of this behaviour.
The solution to this problem is to use try-catch blocks around code that is likely to fail in this way, so that the code fails gracefully, which should be how you are coding anyway.
Related posts:
- Better JavaScript error handling with DamnIT We all know that the Internet is a mess, with...
- Dygraphs Javascript Visualization Library Drawing graphs has become simpler in Javascript, with the dygraphs...
- PHP functionality from within Javascript Most PHP programmers have to deal with Javascript in some...
- Javascript library for functional programming support Javascript has a fair bit of functional programming built right...
- How to dump a Javascript object When trying to debug Javascript, objects can be a real...
Related posts brought to you by Yet Another Related Posts Plugin.
Serge Meunier is a software developer living in Cape Town, South Africa. He loves programming, fencing, philosophy, feeding his internet addiction, and, of course, dogs.
Comments