Welcome!

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

SignUp Now!

Handle a terminating error (exception) within a scriptblock

Aug
1,917
68
While TCC already has ON ERROR, enhance TCC with an additional means to trap and handle errors.

I suggest a TRY CATCH FINALLY exception handling syntax, similar to what C# and other languages have.

Joe
 
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
 
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."
 
Back
Top