Re: Try/Catch

new topic     » goto parent     » topic index » view thread      » older message » newer message
DerekParnell said...

In order to further the conversation, here is a paper that has some interesting things to say about exception handling.

Blimey, I knew things could get messy, but that's just insane. Not compensation stacks per se, but the mess they were intended to deal with. If 1,300 bugs in 27 applications (and the rest, given the lengths the authors go to stress false negatives and unchecked exceptions) tells me anything, it is that we are not looking at something we should want to replicate, whether or not someone has designed a clever mop. Even less when the inventors of said mop concede it could go horribly wrong and isn't really any better than disciplined if-close or much simpler logging.

My choice quotes:

that paper said...

While try-catch-finally is conceptually simple, it has the most complicated execution description in the language specification [Gosling et al. 1996] and requires four levels of nested “if ”s in its official English description. In short, it contains a large number of corner cases that programmers often overlook.

that paper said...

In addition to exceptions, finally clauses also interfere with return, break and continue statements in a similar manner.

Some suggested simplifications:

  • Any try/catch construct in Eu traps ALL exception types.
    (Said constructs can of course be nested to any depth, eg my_application/database/raw_io.)
  • Any and all resignalling, if desired, must be explicitly coded.
  • Lastly (I bet you can guess this one) ditch "finally".
    (There is already a perfectly viable alternative in the form of delete_routine().)

Also, I came up with an analogy that might be appropriate, which expresses some of my documentation-level concerns:
Exception handling is a bit like a skiing accident - you get air lifted to hospital, patched up, given time to heal, and eventually shown the door. These things happen as fast as they can, but to be honest it is not a particularly clever way to get a free cup of tea. You've probably only got one ski boot, half a ski, and your salopettes have been incinerated. If you want to try going skiing again, then that's up to you. What never ever happens is that you get an air lift back to the middle of the ski slope to continue your skiing run from where you left off. But at least you're not dead, which you would inevitably be without the help of the medics, and the same for exception handling.

Pete

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu