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

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s