Exception not being hanlded?Monkey Programming Forums/Monkey Programming/Exception not being hanlded?
| This doesn't handle the exception:|
Function Main() try Local a:List<String> a.AddLast("Hello!") Catch err:THROWABLE Print "Handled!" End Try End
I'm posting this here as I'm not sure it's a bug or not, but looks very weird.
In Monkey, null object, array index and int divide by zero errors aren't exceptions, but runtime errors.
Runtime errors can't be caught - they are bugs in your program that need to be fixed. The Error function also generates such runtime errors.
I may add an OnError() handler similar to OnCreate() to allow you to execute some last minute cleanup code etc. in case you're writing code for nuclear reactors in Monkey, but in general the above errors should be considered 'irrecoverable'.
There are several reasons I didn't attempt to convert runtime errors to exceptions...
* Getting consistent behavior on all targets/all configs would have been difficult. ie: I would have had to enable runtime array index checks on the c++ release target, and added some divide by zero checking to JS/AS. Likely more. But IMO the above errors are programming errors and your app *shouldn't* continue anyway.
* The monkey modules are not necessarily 'exception safe', and writing exception safe code is not trivial...
So, if the list or mojo or whatever module were to throw an exception, with the way the code is now, there's just no way your code could assume everything was hunky dory and continue anyway.
I may add an OnError() handler similar to OnCreate() to allow you to execute some last minute cleanup code etc. in case you're writing code for nuclear reactors in Monkey
Non-safety-critical systems need to catch errors and log failure information too.
| It's ok, just wanted to be sure it was not a bug on the new exceptions implementation.|
EDIT: I'm a bit with muddy-shoes here. Who says a Super Star Soccer match is not critical? hehe. Now, being serious, one of the things I really love about C# or Java is that you can get a lot of information when an exception occurs (call stack as instance) and it can help you a lot narrowing things on complex realtime applications (you know the typical bug that only happens when the user makes a chain of things in an specific order etc.) In this areas, being able to catch exceptions and inspect whatever has gone wrong by inspecting the call stack information that was involved in the exception being thrown can be very useful. I supose it can be way too complex, so maybe it should not be a priority, I don't know... This is just my impression on Monkey exceptions. Maybe it should be left this way, and expect this level of detail to be done into the native languages. I have never touched anything like expections on C++ or ActionScript, so I understand it may not be possible.
| Have you seen the mention of BlitzMax on the article about exception safety? It's cool :) |