HN2new | past | comments | ask | show | jobs | submitlogin

The title of this HN submission is subtly misleading. The original post discusses the fact that Java's exceptions are slow, but merely as a symptom of the main problem: Java mixes up the issues of (a) finding some code that knows how to handle an exceptional condition and (b) backing up the call stack until it can find some code to continue executing. In Java, (b) is unavoidable, so the context of every exception is destroyed before the exception handler can examine it.

As noted elsewhere in this discussion, this means that Java exceptions aren't resumable [1] and that a Java exception can't examine all the variables that were alive when the exception was thrown and take action (like: logging) based on the values of those variables [2]. Plus there may be memory-usage implications. All of which are dimensions of suck that are independent of the speed issue.

---

[1] Not that I really know what this means, having never learned a language where this was possible.

[2] This, on the other hand, would be win that I could understand.



Couldn't [1] be implemented quite simply by some sort of exception handler manager thinggie?

Exception.OnThrown += LogThrownException;

Where this callback has some signature which can examine the stack, locals, and potentially resume?


By doing this you will get something highly similar to CL's conditions. In CL, there is mechanism similar to Java exceptions (throw/catch/unwind-protect) that is - among other things - used by condition system to actually unwind stack when it determines that is necessary. So you can probably abuse Java exceptions to implement condition system or - more generally - escape continuations.

Problem is that such mechanism has to be used consistently everywhere to be useful. And when you find yourself rewriting standard library, you could well use CL instead of Java.


Sure... It's an interesting comparison, and there are trade offs with both systems. I can't see one as being clearly superior to the other though.


Can you elaborate on what you view as the downsides of the Lisp approach?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: