Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Done Test error code in ON ERROR routine

May
12,846
164
It would be nice if _SYSERR or some similar internal variable were available in an ON ERROR routine so that errors could be selectively ignored or processed.
 
From V22 Help:
When handling an error condition with ON ERROR[MSG], you may find it useful to use internal variables, particularly %_? and %_SYSERR, to help determine the cause of the error.

TestOnError.btm
Code:
On Error (*set err=%_? & goto Next)
*dir /nfv testonerror99.exe
:Next
echo. & echo No such file in %_cwp & echo.
@echo err=%err
@echo Errorlevel: %err
@echo `_?` === %_?
quit
Outputs (both V22 & V23):
Code:
v22.00.41_$TestOnError.btm

No such file in \BAT\test02

err=2
Errorlevel: 2
_? === 0
v22.00.41_$

v23.00.1_$TestOnError.btm

No such file in \BAT\test02

err=2
Errorlevel: 2
_? === 0
v23.00.1_$
This seems to meet your suggestion.
What am I missing?
 
_? only produces 0, 1, 2, or 3 ... not indicative of what failed. The actual error below is 5.
Code:
v:\> cdd "e:\System Volume Information" & echo %_?
TCC: (Sys) Access is denied.
 "e:\System Volume Information"
2

v:\> echo %@errtext[5]
Access is denied.

And _SYSERR is not available in an ON ERROR routine.
Code:
v:\> type oe.btm
on error ( echo the error was %_syserr )
cdd "e:\System Volume Information"

v:\> oe.btm
the error was 0
 
Under Window 10 x64:
Code:
v22.00.1_$*cdd "c:\System Volume Information" & echo %_syserr
TCC: (Sys) The system cannot find the path specified.
 "\System Volume Information"
3
v22.00.1_$*cdd "c:\System Volume Information" & echo %_?
TCC: (Sys) The system cannot find the path specified.
 "\System Volume Information"
2
If I execute oe.btm my results are different than yours.
Code:
v22.00.1_$type oe.btm
on error ( echo the error was %_syserr )
*cdd "c:\System Volume Information"
v22.00.1_$oe
the error was 3
Perhaps the results differ because of the Windows version.

In any case I hope Rexx understands what you are suggesting.

I think the suggestions text explanation could be more concise. Examples are great so long as they are valid for the future of TCMD/TCC.

Oh well, you pointed to an inconsistency in how the variable %_syserr is set. When the command is successful I expected _syserr to be set to 0.
Also, when I have a "...The system cannot find the path specified..." (syserr 3) and I then have a "..The system cannot find the file specified..." the syserr variable doesn't change values in a batch file using ON ERROR.
 

Similar threads

Back
Top