How do you catch errors?
BlitzMax Forums/BlitzMax Programming/How do you catch errors?
| ||
Just a simple question, how do you usually go about catching your potential errors? Im asking this because I cant really find a way to do it that looks clean in BlitzMax. |
| ||
Try Do something that causes an error.. I dunno, blow up a kitten Catch o:Object If o Then Print( o.ToString( ) ) End Try |
| ||
Sidenote: BMs own modules do, beside a few exceptions, not throw any exceptions at all so you won't be able to catch anything ... |
| ||
Do something that causes an error.. I dunno, blow up a kitten That won't cause an error, just mess and outrage from the RSPCA |
| ||
Actually a lot of stuff seem to throw exceptions which would be seen as a crash in release builds. (File functions especically), but I usually just return true/false from my funcs and have a last error that can be queried or an error handler that's called. |
| ||
Only the OS related parts throw exceptions (IO, null device and the like). None of the regularly used modules throw any exception at all. All they do is return null and other "impossible" values, that force you to do any exception handling manually ... Quite painfull actually. |
| ||
Max's error handling (throw and catch) is pretty standard, safe and clean. However I tend to write lots of function wrappers that check the return result and error accordingly. |
| ||
I'd avoid getting errors in the first place by making all user-input foolproof, clipping function parameters etc. |
| ||
It doesn't seem possible to catch exceptions such as opengl not being able to open a context in fullscreen mode? |
| ||
It does not throw one. Blitz standard behavior is returning 0, null, "" if something does not work. It only throws error on stuff where a not catched error would have serious consequences. You would need to write your own wrapping functions that throw the needed exceptions ... :( *BM is still far too much focused around the old blitz way of doing stuff and procedural and missing many of the OO capabilities and Pros* |