Re: Try/Catch
- Posted by dcuny Feb 12, 2015
- 4341 views
In 99.99 % (or thereabouts) of cases the programmer will NOT know what that correct runtime value is. Insisting otherwise is completely absurd!
You're not going to try to provide a value for a bad index. Rather, you'll try to structure the program so that it can recover from an action that failed because of an exception.
What that recovery is depends on the application. For example, here's the "recovery" on an attempt to open a file that failed because of some exception:
... case OPEN_FILE then try open_file(fileName) catch e alert("The file " & fileName & " could not be opened. " & e[EXCEPTION_MESSAGE]) end try ...
On the other hand, a developer might simply try to prevent their program from dying by wrapping the top level:
-- handle events until exitProgram is true while not exitProgram do -- is there an event to process? if eventInQueue() then try -- handle the event process( getEvent() ) catch e alert(e[EXCEPTION_MESSAGE]) end try else -- release the cpu pause() end if end while
It's up to the developer to decide at what level it is appropriate to try to catch exceptions. Generally, these will be fairly high up - not at the low level that you're focusing on.
- David