Handle a terminating error (exception) within a scriptblock

rconn

Administrator
Staff member
May 14, 2008
11,894
133
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