Exception would automatically close the game?

Started by Role, February 20, 2005, 17:34:00

Previous topic - Next topic

Role

Why if there is exception in the game, the game is automatically quit? (calling System.exit(0); I think)
When I use Java2D and JOGL, whether there is uncatch exception, I create a thread and built up a notification frame to show the user the exception.
But if I use LWJGL the game will automatically quit if there is uncatch exception.
I guess LWJGL force to quit if there is no other active thread beside thread that throwing the exception (the thread that showing notification frame is in a daemon thread).
Is this on purpose or not? But why is that?
D Java Game Engine
GTGE  Website | GTGE Forum

Chman

I think it's more safe to exit the game when an exception occurs. A finished game shouldn't have any bug. If a lwjgl exception happens and the game continue, it could make the computer crach, which is not very cool for the user :?

Chman

tomb

you wrote:
QuoteWhen I use Java2D and JOGL, whether there is uncatch exception, I create a thread and built up a notification frame to show the user the exception.
From java.lang.Thread.setDaemon(boolean) javadoc:
QuoteThe Java Virtual Machine exits when the only threads running are all daemon threads.
So if you create a deamon thread at the end of the main thread, the following is probably happening:
1) main thread creates deamon thread. The deamon thread will later show a frame
2) main thread exits. The only other threads running is the one just started. But because it's a deamon thread, it closes the application.

So either don't make it a deamon thread, or show the frame from the main thread.

Role

Thanks, I change the thread to non-daemon, and it's working :)
This is must be because LWJGL architecture is somewhat different with Java2D (AWT) architecture.
Cos in Java2D or JOGL (using AWT Frame), if there is exception, the game is CRASHED and HUNG (I guess there is still a hanging active main thread in here), and that's time for me to create exception frame in a daemon thread and wait for the user to press quit button.
But in LWJGL, if there is exception, the game immediatelly is CLOSED (no other main thread is active).
I use daemon thread at first is for workaround in applet environment, cos when in applet environment, sometime the thread (that makes the exception frame) creation is interferred by the applet process, so to make sure everything is fine, I use daemon thread to create the exception frame.
D Java Game Engine
GTGE  Website | GTGE Forum