Pre-Set Error Levels

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MLGsuperGame414
Posts: 54
Joined: 10 Nov 2011 20:40

Pre-Set Error Levels

#1 Post by MLGsuperGame414 » 14 Nov 2011 15:48

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!

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Pre-Set Error Levels

#2 Post by Ed Dyreen » 14 Nov 2011 16:18

'
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
however this one does:

Code: Select all

set /a $error = hello
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.

Post Reply