Hacker News new | ask | show | jobs
by chrisseaton 2326 days ago
> Most performant: never.

I disagree. An exception can be faster than manually unwinding a set of nested scopes.

1 comments

Most exceptions, at least in the JVM where this is commonly debated, will incur a penalty of building up the exception and unwinding the call stack. What aspect of performance are you using as an example?
An exception thrown and caught within a compilation unit is effectively a goto. It can translate into nothing more than a jcc instruction, or even nothing at all if it's unconditional. This can be higher performance in practice than threading through a set of Either-style return objects.