Batch File try catch
batch-file
Solution
Standard method for batch files to handle errors is to use ERRORLEVEL variable. Zero means no errors, non-zero - error:
@rem some code
if %ERRORLEVEL% neq 0 goto ProcessError
@rem ... other code
exit /b 0
:ProcessError
@rem process error
exit /b 1
exit /b exitCode sets ERRORLEVEL to this exitCode.
Problem
I have a batch script with the statement as shown below: ``` for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set TIME=%%j set TIME=%TIME:~0,12% ``` But once I executed it returned an error which I couldnt understand first. Then got to know the error was because of missing the wbem in path env variable. This bat file is located in a central repository so that anyone can execute this. So, need to let the user know the reason if this error strikes again in their local machine. I dont think there is a try catch statement in Batch. Also, known about ErrorLevel. But I am not sure how this can be implemented..Can anyone support me in this regard..