11 ms·
AbhiramaVS I think your choice to use exceptions is fine, it matches closely with Java / Python your inspirations. The "show me every error" crowd loves to har
by program_whiz 1mo ago
AbhiramaVS I think your choice to use exceptions is fine, it matches closely with Java / Python your inspirations. The "show me every error" crowd loves to harp on this issue, but the truth is, its a tradeoff like all others.
Exceptions provide flexibility in error handling, and most code just forwards and you end up in the same situation anyway. Something like this (go style):
if result, err := do_thing(); err != nil {
log.errorf("Got an error! %v", err);
return err;
}
Or the rust equivalent isn't super useful, the code is just outputting an inferior form of stack tracing and debugging.
Honestly unless the code at the immediate site of the error can handle the issue, or perhaps one level higher, having precise error information (usually obscured by some generic Error class anyway) isn't very helpful, and ends up propagating up to a high level where the whole thing is terminated / cleaned up anyway, which is what exceptions provide automatically.
Also, only catching the things that you can deal with and know about is useful in the sense it keeps code flexible (e.g. you don't handle a DiskFull exception because the only thing you can do with it is throw anyway, and if you had a DiskFull error returned, you would just return it up the stack / panic). As new unhandled errors emerge, you just throw them up the stack, the same way error code would, except errors just require you to explicitly manage the machinery everywhere, requiring rigid, over-specified, fragile code in many cases.
I do see the argument for explicit errors especially in system programming, realtime / perf-critical, kernels, etc. But this language doesn't appear to be targeted at that, and uses GC. So having exceptions seems like a valid design choice to me. Using them also frees you a bit since you can pass around functions, captured references, threads, etc. in a bytecode + GC lang without worrying to much about the error states and memory ownership.