Hacker News new | ask | show | jobs
by rkagerer 1264 days ago
What's keeping exceptions out of Zero?

Is there a simpler way you could achieve Try/Catch semantics and throw-like flow control, without having to check return values after each function call? eg. Even though VB6 lacks exceptions, I built such a framework for it out of primitives like "On Error Goto" (and helper tooling that would automatically wrap and instrument functions to propogate the Err details). It sounds a bit heavy but was in fact really slick in practice.

2 comments

TL;DR: It's work.

The way exceptions are done in .NET is by keeping track of extra metadata to be able to unwind methods (remove them from the execution stack) and execute handlers. That way the overhead of exception handling is close to zero if no exception is ever thrown. This requires quite a bit of infrastructure.

Propagating exceptions as error codes would come with execution time costs even if no exception is thrown and would have to be written from scratch (since .NET doesn't do it this way).

Either approach requires more investment than I'd want to put into it right now.

Note that .net supports exception filters (and the stdlib uses them), so replacing exceptions with error codes would observably change behavior in a big way.