• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Command Window Shutting Down....

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,


Why would a java command line program close the command prompt itself after an exception is thrown? I ran the program from the command prompt, and when a exception was thrown the command window was shut down.


We were trying to get a stacktrace when the exception happens, but since the window closes we are not able to progress.
We also tried logging the exception or even manually writing the exception stacktrace to a file, but the exception object is null.

So any idea why the command window is itself closing?

Thank you
Pradeep
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The command process will exit under normal program termination conditions and when exceptions cause the program to terminate (this is normal under windows). You should use a logger or as you have done, write the exception to a file. Perhaps you have saved the cause of the exception and this saved the value "null" ? Which could mean you have a NullPointerException. Can you post some code here ? Why not use a debugger to step through the program and figure out where the error occurs ? Or if you have an idea about where the exception occurs try to read data from the console ( kind of crude I know ). This would stop execution until you type something in and you can read your stack trace (assuming you threw it to the console).
 
pradeep selvaraj
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks John,

Well the code is something like this....


I had no idea that a java program could shut down the command window. And it never happens in when we test it only happens in the live environment. And we wont we able to simulate the live environment here. Thats why debugging too wont help us either. I am now able to get the stack trace written to a file as the code above does. But strangely after the exception the logger only throws junk values.

Could you please explain why a command window would close, when an exception occurs, because i open the command prompt and run the program. Even if an exception is not caught, it should only kill the program and show the promt right?


Thanks John

pradeep
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Even if an exception is not caught, it should only kill the program and show the promt right?


That is certainly what I would expect!
What is the "live environment" and how is it different from the test environment?
If this was my problem the next thing I would try would be executing the program from a batch file with additional operations after the program call.

Bill
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to add something. If you start the program after you are in command prompt (Start -> Run -> cmd ), you can see the exception on the screen after the program dies (either you throw the exception to the console or the JVM ) and the command prompt will not close. If you execute some kind of shortcut from windows that runs your program, the command prompt will open, and if the program dies (or finishes execution normally) the command prompt dies with it.

May be your live environment has a shortcut to run the java program and the prompt then opens up. The unhandled exceptions kill your process or there is no more code to execute after the exception is caught. This would be my guess.

What do you mean by - the logger throws junk values ? Are you not able to trace what kind of exception is thrown and its root cause ? Can you post what your saved file looks like ?
 
pradeep selvaraj
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to both of you

Yeah i did go to (start->run->cmd) and then execute the program, thinking that even if we hadent cought that exception there would be a stack trace printed. But two time the program has shut down and both the time the command window has also been shut down. I dont think anyone on the client site would close the window, because we have told them specifically not to do it.

Now we are able to write the stacktrace to a file before it shuts down. But i am still wondering how the command prompt would close when i ran the application by going to start->run->cmd.

Any idea if that is possible by java to do that when an exception is thrown?

Thanks
Pradeep
reply
    Bookmark Topic Watch Topic
  • New Topic