I want an app that throws an exception from a button.
The exception should then shutdown the application (unhandled exception).
( I need that to check my code in Runtime.getRuntime().addShutDownHook()
)
So I wrote this
button1.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
throw new NullPointerException("");
}
});
And tried also tried throwing a RuntimeException, but the application did not close.
Any suggestion how can I close my app due to an exception?
Thanks.
EDIT
I will explain -
In the Java docs - http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)
it is noted that when you write a JVM shut down hook - make it a fast running piece of code. Quote:
"Shutdown hooks should also finish their work quickly...."
My code is running a bit longer and I wanted to test it by an exception (and not System.exit() - though it should be the same, but sometimes the results are not the same)
Just wondered how you throw an exception from a button (I know the code is bad, it's for testing ).