How to pause cmd window incase of any exceptions.

Last year I had to write a small piece of java code to launch another application using one of the available ports between certain range. I wrote the code and saved the command to launch the java class in batch file so that when the user double clicks it, java class will launch the application.

There is a small catch here. The cmd window does not pause irrespective of how the program runs. If the program runs successfully, then fine. But how will the user know in case of any exceptions? So we need to add one line in the batch script at the end to pause the cmd window in case of any exceptions so that the user will get the chance to see what the exception is. The following line is what needs to be added so that the cmd window pauses in case of exceptions:

IF %ERRORLEVEL% NEQ 0 pause

Published by Chaitanya

I am a family man, perpetual learner, coffee drinker, dessert eater and Happiness Engineer at Automattic. I also read, write, move, and meditate.

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: