Handle a terminating error (exception) within a scriptblock

rconn

Administrator
Staff member
May 14, 2008
12,425
153
TCC (and Take Command) already do that internally. The only time TCC will crash is when calling a Windows (or third-party) API when that API substitutes its own exception handler and throws a fatal exception on an error.

Or are you asking for a user-configurable exception syntax?
 
Using current error trapping;
Code:
@setlocal
@echo off
type foo.txt 2> nul
if %? eq 2 (
  echo File foo.txt does not exist
)
echo type returned error code %?
endlocal

Using Try/Catch/Finally;
Code:
try
  type foo.txt
catch 2
  echo File does not exist
finally
  :: Code to execute whether or not an exception is raised
  echo type returned error code %?
end try

This is just a simple example.

Joe
 
Jan 16, 2011
15
0
TCC (and Take Command) already do that internally. The only time TCC will crash is when calling a Windows (or third-party) API when that API substitutes its own exception handler and throws a fatal exception on an error.

Or are you asking for a user-configurable exception syntax?
I use TCC to test my students' Java programs. I'd love to be able to catch their buggy programs' exceptions and be able to report at least the exception's name (e.g. java.lang.NumberFormatException). I can detect ERRORLEVEL GT 0, but I'd like to report a finer level of detail than "something bad happened."
 

Similar threads