Jun 25, 2011

Always define ExitCode while using exit/b!

I think I encountered very rare case in which exit/b caused ERRORLEVEL to set to non-zero outside the procedure. I do not know how did it happen, but I know exactly it was not caused by SET returning ERRORLEVEL on flushing absent variable:

set var=123
::ERRORLEVEL = 0 - even, if var was previously 123 
set var=
::ERRORLEVEL = 0 - variable terminating successful
set var=
::ERRORLEVEL = 1 - variable does not exist

I will probably never discover the cause of the problem, because exit/b was itself a problem, not overlapping SET commands. My advice is: always use exit/b0 instead of same exit/b. This will save you time, as while working on complex procedure it may cause you a headache, and code may become more readable if you are happy about hard typing.

No comments:

Post a Comment