Try Catch?
BlitzMax Forums/BlitzMax Beginners Area/Try Catch?
| ||
What does a try catch ?, is something new that is not Blitz3D |
| ||
It catches exceptions trown within it, exceptions can be any Object.Try doit() Catch e:Object Print "oops: " + e.ToString() EndTry Print "done" End Function doit() Print "enter" Throw "ERROR" Print "leave" EndFunction |
| ||
@grable.Method G3D() Try If( xGfxModeExists( Self.anchoPantalla:Int, Self.altoPantalla:Int, Self.pdadColor:Byte )) xGraphics3D ( Self.anchoPantalla:Int, Self.altoPantalla:Int, Self.pdadColor:Byte, Self.modoVentana:Byte, Self.vSync:Byte ) xSetBuffer( xBackBuffer() ) Else Throw "Graphics3D" End If Catch t$ Print "Error :" + t$ End EndTry End Method Ok? |
| ||
Well it works. But i see no reason to use it in that case, as you are in the same scope. Its better to use Try/Catch around code that might throw exceptions deeper in the call stack, usually by things you have little control over. Also notice that when thrown, it unwinds the stack and returns the program to any outer Catch statements of which there can be multiple levels. To let another level handle the exception it then has to be re-thrown. Btw, its generally bad to use exceptions for control-flow. Exceptions should be exceptional ;) |
| ||
Ok, Thanks You. =) |
| ||
There's some more information here: http://www.blitzbasic.com/Community/posts.php?topic=105700 |