How do you catch errors?

BlitzMax Forums/BlitzMax Programming/How do you catch errors?

Regular K(Posted 2006) [#1]
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.


N(Posted 2006) [#2]
Try
  Do something that causes an error.. I dunno, blow up a kitten
Catch o:Object
  If o Then Print( o.ToString( ) )
End Try



Dreamora(Posted 2006) [#3]
Sidenote: BMs own modules do, beside a few exceptions, not throw any exceptions at all so you won't be able to catch anything ...


Boiled Sweets(Posted 2006) [#4]

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


ozak(Posted 2006) [#5]
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.


Dreamora(Posted 2006) [#6]
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.


Grey Alien(Posted 2006) [#7]
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.


CS_TBL(Posted 2006) [#8]
I'd avoid getting errors in the first place by making all user-input foolproof, clipping function parameters etc.


ImaginaryHuman(Posted 2006) [#9]
It doesn't seem possible to catch exceptions such as opengl not being able to open a context in fullscreen mode?


Dreamora(Posted 2006) [#10]
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*