Re: Try/Catch
- Posted by Spock Feb 15, 2015
- 4152 views
Try/catch would therefore seem to have an advantage if the SSC handler couldn't properly clean up. OTOH, try/catch itself must also attempt a difficult clean up if it is to keep the program running.
You'll generally wrap the try around a discrete action - load a file, save a file, etc. - so that if some portion throws and exception, you know the data structure you were expecting wasn't created properly, and can't be trusted for use.
- David
As you pointed out right from the beginning, cleanup() in the exception handler would have a huge job to do. One of my graphics-based programs does a lot of manipulation at the raw byte level. Routinely blocks of RAM are allocated at 50MB per image or operation. One or two routines also access memory that Windows temporarily allocates. Naturally, memory leaks of such magnitude per unit must never happen.
If an exception occurred x levels down in such a situation the clean up required would be just insane. With SSC this clean up will happen automatically as part of each routine's normal exit strategy. So in this aspect it must be superior to try/catch.
SSC might not be "better" than try/catch but is it materially worse? In some ways it might be simpler to implement.
I think that many of the points for try/catch have already been made:
- It is a well-established, understood and accepted way of handling exceptions.
Agreed. I'm not aware of Spock's SSC being used anywhere (though I'd love to see some real life usage examples of it).
It's just error codes that have been around forever. Only smarter, less intrusive.
Whatever OE might implement I'm sure I won't regret adding SSC to my own compiler.
Spock