

Unlike exit, in which you can set an exiting errorlevel, goto :eof automatically sets the errorlevel to the currently set level, making it more difficult to identify problems.goto :eof ends the current script (call) but not the parent file, (similarly to exit /b).You could create separate :labels for different errors, and have each return a unique error level.

Setting error levels with this method can be useful when creating batch scripts that may have things that fail. offĬall :getError rem Calling the :getError labelĮcho Errorlevel: %errorlevel% rem Echoing the errorlevel returned by :getErrorĮxit /b 1 rem exiting the call and setting the %errorlevel% to 1 For example, exit /b 1 would produce an %errorlevel% of 1. With exit, you can also add an error level of the exit.

The normal exit command simply terminates the current script, and the parent (for example if you were running a script from command line, or calling it from another batch file)Įxit /b is used to terminate the current script, but leaves the parent window/script/calling label open.
