Pre-Set Error Levels
Moderator: DosItHelp
-
- Posts: 54
- Joined: 10 Nov 2011 20:40
Pre-Set Error Levels
Okay, I am working on a simple project that doesn't require much complicated coding its very simple coding that couldn't possibly have errors. But hopefully later on it will be more advanced I was wondering if I could add an Error system before I really need it. For example have some lines of code that if found will tell you theirs an error. Like another batch file coded just for finding errors and setting the error levels. I'm fairly new to Batch coding so please if there is a way lay it on so a noob could understand it. Thanks!
Re: Pre-Set Error Levels
'
Every time you leave a function you can use exit /b %errorlevel%,
you can also set the errorlevel inline cmd /c exit %errorlevel%.
All external and internal commands probably return errorlevels, these can be captured for u to examine.
Next command produces no error:
however this one does:
There are 2 techniques that are quite popular to print error messages to users.
The first one depends on a file being enumerated when the error occurs,
the 2nd is accessing it by a predefined array.
Both are good against redundancy which could lead to inconsistency.
But this is only useful for moderately complex scripts.
Every time you leave a function you can use exit /b %errorlevel%,
you can also set the errorlevel inline cmd /c exit %errorlevel%.
All external and internal commands probably return errorlevels, these can be captured for u to examine.
Next command produces no error:
Code: Select all
set /a $error = 0
Code: Select all
set /a $error = hello
The first one depends on a file being enumerated when the error occurs,
the 2nd is accessing it by a predefined array.
Both are good against redundancy which could lead to inconsistency.
But this is only useful for moderately complex scripts.