Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Following up my previous question I wonder if resumable exceptions make any sense. It looks like nobody uses them in Java. Don't they use resumable exceptions because of Java limitations or just because they don't really need them?

Suppose, I want to create a file in a directory, which should exist but does not. I would probably prefer use a resumable exception (i.e. throw an exception, catch it and create the directory, and resume the execution) instead of testing if the directory exists every time I create a file. Does it make sense in general ?

share|improve this question
2  
(Java has resumable exceptions? I'd imagine they are unused due to lack of ... support.) In any case, I am not fan of the idea in general -- but this is likely because I was not weened on SmallTalk or CLISP and only have bad memories of on error RESUME next. –  pst May 28 '11 at 6:54
    
Java does not have resumable exceptions and this question is a bit too argumentative for SO, I think. –  Kim May 28 '11 at 7:23
    
It would probably be hard to implement resumable exceptions in Java since it doesn't have resumable continuations. In any case it wouldn't be too elegant to use IMO. –  haknick May 28 '11 at 12:34
1  
Actually, resumable exceptions can be implemented without using continuations. You really only need a global exceptionHandler variable, which is set to a new handler in the extend of a try/catch block, and raising the exception is simply calling exceptionHandler. However in Java this would be way too verbose. –  hzap May 28 '11 at 17:52
1  
Resumable exceptions make it trivial to implement delimited dynamic variables. –  Frank Shearar Jun 26 '12 at 15:05
add comment

migrated from stackoverflow.com May 30 '11 at 17:54

This question came from our site for professional and enthusiast programmers.

2 Answers

Not directly related to Scala, but when the C++ exception mechanism was being designed, there were big arguments about resumption. Eventually, they looked at a very large codebase (not of C++) where resumption could have been used, and found only one instance of it, which could easily be re-written not to use it. Also, C++ committee members who had used resumption were solidly of the opinion that it caused nothing but problems. So it was decided that C++ should not support exception resumption. Designers of most other languages seem to be of the same opinion.

share|improve this answer
    
+1 hear hear. If you need to resume some operation after an exception, just structure your code in such a way that you can easily do it explicitly, whether by re-invoking the failed function or otherwise. Hell, use a goto if it excites you. –  Jon Purdy May 30 '11 at 18:41
add comment

I believe resumable exceptions are more useful in language platforms where it is feasible to catch an exception, use the debugger to isolate the problem, change the code to fix the problem, and update the running system with the new code before resuming the program. Think the Lisp Machine, and maybe Smalltalk. Modern systems have moved away from that level of interactivity; I've never used a system like that (except emacs, but I'm a shallow emacs user), so take my answer with a grain of salt.

Note that resumable continuations are similar to continuations, which have other uses in their own right.

share|improve this answer
1  
Smalltalk definitely supports resumable exceptions. Common Lisp, too. Certainly in Smalltalk it's not a particularly rare technique. –  Frank Shearar May 31 '11 at 10:04
    
Users (as opposed to smalltalk programmers) who find themselves being dumped into the debugger may wish it were rarer. –  nbt Jun 5 '11 at 15:50
1  
@nbt Resumable exceptions have nothing to do with bugs that drop users into debuggers. –  Frank Shearar Aug 21 '12 at 20:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.