my question is simple. How to force JAVA to terminate the program I am writing when any Exception occures?
I am currenlty using Swing and when a NullPointer exception is thrown, the program keeps on running in the background 😐 While running this way I can only close it from the task manager. The bad thing is that when I run the same program again, a second instance is created and I don’t know why, but when I have more than 1 instance of the same program, one time I get null exception, next time not, next time yes, next time not…. Complete randomness.
Thanks in advance!
Obviously it seems that your program has at least a bug that you can try to iron out with a debugger.
As for your question, an exception will terminate your program if it isn’t caught. So if you always throw your exceptions, including in the main method, when one happen will cause the program to exit.
However, as Mac said in the comment