Re: Try/Catch
- Posted by Spock Jan 13, 2015
- 5197 views
As for the tedium of having to check the error code each time, we do this already for calls like open() etc.. I think the error treatment of many calls is context dependent (ie, caller driven) and I personally prefer the freedom of being able to specifically choose when to check any error codes.
One thing try/catch does better is that if you forget to add a check, then the program crashes - so you get fail fast development. Your version doesn't seem to have that (unless you're suggesting that the interpreter crashes when it detects somehow that ERR is set but the caller doesn't check it).
You misunderstand. An error doesn't crash anything though the bad data that prompted it could cause havoc at a higher level. However, an exceptable situation already has a check inside the internal routine which, in the suggested scheme of things, will default to a 'safe' behaviour instead of crashing. That doesn't solve the program error in the first place but it can alert us to the fact.
So how is try/catch better?
Spock