SetTryErrorCode

Syntax:

SetTryErrorCode(Code.l)

Parameters:

Code.l

=

Error code


Return Values:


Description:

Sets a type of exception. The error code is returned by GetTryErrorCode(). Use this function only in the If part (error handled section), when used outside it will lead to a crash or debugger error.

A list of standard error codes (not all are supported for every computer):

#EXCEPTION_ACCESS_VIOLATION

#EXCEPTION_ARRAY_BOUNDS_EXCEEDED

#EXCEPTION_BREAKPOINT

#EXCEPTION_DATATYPE_MISALIGNMENT

#EXCEPTION_FLT_DENORMAL_OPERAND

#EXCEPTION_FLT_DIVIDE_BY_ZERO

#EXCEPTION_FLT_INEXACT_RESULT

#EXCEPTION_FLT_INVALID_OPERATION

#EXCEPTION_FLT_OVERFLOW

#EXCEPTION_FLT_STACK_CHECK

#EXCEPTION_FLT_UNDERFLOW

#EXCEPTION_ILLEGAL_INSTRUCTION = $C000001D

#EXCEPTION_IN_PAGE_ERROR

#EXCEPTION_INT_DIVIDE_BY_ZERO

#EXCEPTION_INT_OVERFLOW

#EXCEPTION_INVALID_DISPOSITION = $C0000026

#EXCEPTION_NONCONTINUABLE_EXCEPTION = $C0000025

#EXCEPTION_NONCONTINUABLE_EXCEPTION

#EXCEPTION_PRIV_INSTRUCTION

#EXCEPTION_SINGLE_STEP

#EXCEPTION_STACK_OVERFLOW = $C00000FD


Example:

; Although this is not really a good example to use exceptions,
; it works :)
; I think it will give you the idea of exceptions and their use!

Enumeration
	#EXCPT_ALessB
	#EXCPT_AGreaterB
EndEnumeration

Procedure test(a.l, b.l)
  If TryError()
	  If a > b
			SetTryErrorCode(#EXCPT_AGreaterB)
		ElseIf a < b
			SetTryErrorCode(#EXCPT_ALessB)
		Else
			MessageRequester("Cool", "Juchee! But now I will produce a cool runtime error ;)")
			CopyMemory(1,1,1)
		EndIf
	Else
 		Select GetTryErrorCode()
			Case #EXCPT_AGreaterB
				MessageRequester("Shit happens!", "Sorry, but A is greater than B!")
			Case #EXCPT_ALessB
				MessageRequester("Shit happens!", "Sorry, but A is smaller than B!")
			Default
				MessageRequester("Error", "An error occured!")
		EndSelect
	EndIf : EndTryError()
EndProcedure


test(4,5)
test(5,4)
test(5,5)

Remarks:

tested with 2k/XP



Supported OS:   Windows