PxPlus User Forum

Main Board => Discussions => Wish List => Topic started by: Thomas Bock on February 12, 2025, 02:37:46 AM

Title: error breakdown with try-catch
Post by: Thomas Bock on February 12, 2025, 02:37:46 AM
Using try-catch allows us to continue program execution but it doesn't provide any useful information about the reason for the exception.

Please take a look at my sample code
begin
try
call pgn+";LABEL1"
catch
print err, " ", err("stno"), " ", err("program")
print "--- error history ---"
maxIndex = prm('EH')
for local i = 1 to maxIndex
print str(i : "##0"),": ", err("err", i, err = *break), " ", err("program", i), " ", err("stno", i)
next
end_try
print "End"
end
LABEL1:
call pgn+";LABEL2"
exit
LABEL2:
call pgn+";LABEL3"
exit
LABEL3:
string2Convert$ = "not a number"
numValue        = num(string2Convert$)
exit

I think it is challenging to provide a complete dump at the point where the error occurs. But it should be possible to provide a small dump of all the variables used in the error statement. That dump could be provided by a new keyword, e.g. err("DUMP").
The information will allow us to find the reason for the exception and apply proper corrections.

Title: Re: error breakdown with try-catch
Post by: James Zukowski on February 12, 2025, 08:41:21 AM
From my reading, you need to first set the 'EH' parameter for it to start tracking errors. By inserting a "set_param 'EH'=20" after the BEGIN, it should provide more information for you, though perhaps not quite as much as you want.