Bladeren bron

Added test for exceptions in tryCatch

Ronny Otto 11 jaren geleden
bovenliggende
commit
89d146dd6c
2 gewijzigde bestanden met toevoegingen van 36 en 0 verwijderingen
  1. 33 0
      tests/framework/language/exception_01.bmx
  2. 3 0
      tests/framework/language/exception_01.res

+ 33 - 0
tests/framework/language/exception_01.bmx

@@ -0,0 +1,33 @@
+SuperStrict
+Framework Brl.Standardio
+
+
+Type TMyException Extends TBlitzException
+	Field message:String
+
+	Method ToString:String()
+		If message = Null  then Return GetDefaultMessage()
+		Return message
+	End Method
+
+
+	Method GetDefaultMessage:String()
+		Return "Undefined TMyException!"
+	End Method
+End Type
+
+print "start TRY"
+Try
+	local tmpObj:TMyException = null
+	if not tmpObj
+		local myException:TMyException = New TMyException
+		myException.message = "assignment to null is not allowed"
+		Throw myException
+	endif
+	tmpObj.message = "123" 'fails
+	print "assignment possible while not allowed"
+Catch ex:Object
+	if not TBlitzException(ex) then print "unknown exception:"
+	print ex.ToString()
+End Try
+print "end TRY"

+ 3 - 0
tests/framework/language/exception_01.res

@@ -0,0 +1,3 @@
+start TRY
+assignment to null is not allowed
+end TRY