java - JavaFX Application keeps running even if i have an error in my main class static initializer -
keeps running:
package app; import javafx.application.application; import javafx.stage.stage; public class test extends application { static { throwanexception(); } @override public void start(stage primarystage) throws exception { } public static void main(string[] args) { launch(args); } private static void throwanexception() { throw new runtimeexception(); } }
stops:
package app; import javafx.application.application; import javafx.stage.stage; public class test extends application { @override public void start(stage primarystage) throws exception { } public static void main(string[] args) { throwanexception(); launch(args); } private static void throwanexception() { throw new runtimeexception(); } }
why?
in first case program keeps running, exception. in second case program stops before calling javafx thread. static initializer should run before main method, right? english vary bad didn't write much. hope understand question.
this kind of cheap answer
it keeps running because there 4(3) other threads running ..
when exit/close/shutdown application through stop()
kill right way, think, main thread
triggered after stop()
method if have exception there, pretty happens after show, if throw exception in init()
method app shutdowns real - init()
method starts 2 additional threads..
replace , see
static { new thread(new runnable() { @override public void run() { while(true){ try { thread.sleep(1000); } catch (interruptedexception e) { e.printstacktrace(); } system.out.println("there "+ thread.activecount()+" still running"); } } }).start(); throwanexception(); }
Comments
Post a Comment