Seite 1 von 1

Exception Handling in Codeblocks

Verfasst: Mi, 18. Okt 2023 15:31
von klammerauf
Hallo,

gibt es eine Möglichkeit, wie ich innerhalb eines Codeblocks eine Exception behandeln kann?

Code: Alles auswählen

cbTest := {|a|b := 20, b / a} 
eval(cbTest, 0)
Ich dachte an irgendwas in dieser Art:

Code: Alles auswählen

cbTest := {|a|b := 20, BEGIN SEQUENCE, b / a, ENDSEQUENCE} 
eval(cbTest, 0)

Re: Exception Handling in Codeblocks

Verfasst: Mi, 18. Okt 2023 16:03
von Marcus Herz
Das geht nur wenn du eine Funktion im Codeblock aufrufst:

Code: Alles auswählen

cbTest := {|a| MyFunction(a,b)} 

STATIC FUNC myFunction(a,b)
local bErr	:= Errorblock({|o| ... })	// hier kannst du noch deinne eigenen Errorblock definieren, wenn nötig
local xRet
BEGIN SEQUENCE
	xRet	:= a / b
RECOVER
END 
Errorblock(bErr)
RETRUN xRet