Re: Try/Catch
- Posted by jimcbrown (admin) Jan 04, 2015
- 6186 views
I think we need to be clear that there are three different things here:
- Error codes return from functions;
- Ensuring resources are properly cleaned up; and
- Handling exceptions
While they are related, they aren't the same thing.
Agreed in full.
Exception handling isn't the same as a routine returning an error code. That's a good thing, and I won't argue against it. But it's a different sort of discussion.
Well, it can get kind of blurry. To use the earlier example,
This isn't going to replace checking return codes from functions like open(). After all, these aren't exceptions.
Except that they are, in other languages like Java. Even worse, some builtin routines in Euphoria fail silently. (E.g. if the filesystem is full, you won't see a return code from puts() warning you that the data you just tried to write was lost. Perhaps there's not much you can do in that case anyways, but it's the principle that counts!) So there's plenty of room for argument that existing routines should have their behavior modified to throw exceptions.
My position is, as a matter of principle, when the language can get away with returning an error code from a routine to signal something, it should do so. If it's something that can't be reasonably handled by a routine returning an error code, that's when it's time to consider throwing an exception....