If there is one thing that can drive me insane is the way in which Javascript handles errors. mybloggingplanet.com
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.
Comments