How can I show a Runtime error?

BlitzMax Forums/BlitzMax Programming/How can I show a Runtime error?

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

I am delphi programmer as well. In delphi all exceptions derive from Exception so typicall you might write

try
..
..
except
 on e:exception do ...
end;
[code]

MAX isnt much differnt and you can catch different types of exceptions.  All exceptions in MAX are objects.

You asked how to catch a runtime error :)

To catch all exceptions
[code]
' Here is one i made up
Type EMyException
	Method ToString:String()
		Return "EMyException- Poopie"	
	End Method
End Type
Type  TApplication
	Method Run()
        Graphics 640,480,0
		While Not KeyHit(KEY_ESCAPE)
			Cls
			If KeyHit (KEY_F1)
				RuntimeError "Poop" ' this throws TBlitzException
			End If				
			If KeyHit (KEY_F2)
				Throw "Poopie"	' This throws a string object						
			End If	
			If KeyHit (KEY_F3)
				Throw (New EMyException)	' This throws EMyException						
			End If	
			
			Flip
		Wend
	End Method
End Type


' Main code notice the try catch that whats important

Try
   (New TApplication).Run
Catch  r:TRuntimeException
	Notify "Runtime "+r.ToString()
Catch  e:String
    Notify "Unhandled"+e.ToString()
Catch  d:EMyException
    Notify "Unhandled"+d.ToString()
End Try


You notice it is very similar. Now you can just catch o:Object and attempt to figure out what it is if you need general handler

Hope this helps.

Doug Stastny