An exception occurs when the Operating System catches a program doing something bad. A typical bug will cause a program to read or write to memory that’s out of bounds; this is a memory exception.
is what a lot of developers seem to do, and it’s something I find very annoying. They don’t add code to catch exceptions. It’s like refusing to build a hospital because you can see no reason why people should get sick.
When the average program crashes – an eventuality virtually impossible to rule out – its allocated memory most likely still contains a perfectly serviceable copy of your valuable data. A simple exception handler (special code which the program provides to be run in the event of an exception) could, in most cases, offer the user the opportunity to save [or at least dump] document data. Most software doesn’t provide this, so when your program crashes you can say goodbye to whatever you’ve been typing for the last half hour.
Programs which have lost me data in this way, I believe unnecessarily:
-
MS Developer Studio – somehow managed to lose an entire file recently, very unusual behaviour, lost about an hour of work.
-
Outlook express – seems to be an issue with the latest version of MS DHTML control on my machine, I can be typing an email and the thing will just crash, apparently randomly.
The thing is, most of the time software creates temporary structures and buffers to manipulate data, then puts it back. The chances that your data is still intact when a crash occurs are actually pretty good, but because of the lack of exception handling you’ll never get to find that out.
Ages ago I added what at first seemed a lazy feature to JujuEdit: should an exception occur, it is "caught" and recorded, and you are given the option of continuing. I say lazy because the proper thing to do is of course to fix an exception, not to catch it. The thing is, this handling actually makes it a lot easier to track down bugs, because I can immediately try to get the exception to happen again [establishing a pattern], rather than having to restart the program in debugging mode and trying to reproduce the situation. [On the few occasions this has happened unexpectedly, I have always found my data still intact.]
To sum up: software should be built with the assumption that it contains bugs, and top priority should be given to the conservation of unsaved data.