Re: Try/Catch
- Posted by dcuny Jan 01, 2015
- 6216 views
I prefer Go's handling of errors compared to exceptions as performed in other languages.
This looks roughly akin to BASIC - On Error Continue, where an Err value is set, but the code doesn't fail. The main difference seems to be that Go returns an Error object, while BASIC has a global value.
However, in Euphoria, there's no such thing as a recoverable error. So in that sense, it's sort of the opposite of how Euphoria handles errors: Euphoria halts, while Go continues, but informs you that an error occurred.
From that perspective, I think it would be a hard sell. That is, it fundamentally alters how Euphoria behaves. On the other hand, try/catch/finally wouldn't actually alter Euphoria's behavior - if you chose not to use them, exceptions would still be fatal.
For cleaning up resources, Go has "defer" which defers the execution of a piece of code until the subroutine exits.
This seems akin to finally. The main difference is that is that finally can be embedded inside of other try/catch loops.
- David