Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Run Function on Exception or Throwable Without try{} block  (Read 811 times)
0 Members and 1 Guest are viewing this topic.
Offline DQQAYME

Junior Member


Medals: 1
Projects: 1



« Posted 2013-04-12 18:19:32 »

Here is problem I have main game thread and using JFrame
JFrame on setVisible create not daemon Thread AWT-EventQueue
So when my main process Thread do all work,
and I don’t have other no deamon thread Application still running
To finish it need or hide JFrame or use System.exit

The problem in error Exception,
The standard way is surround main function
try{}catch or finally
But I need debug in Eclipse start Exception and try{} block skip it.
For fix error in debug mode.

So we need make some action on Exception not using try{}

Here is my solution
Closer Thread something similar like base JVM Check for no daemon

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
public class Closer_Thread extends Thread{
   public Closer_Thread(){
      super();
      setDaemon(true);
      setName("Closer");
      setPriority(Thread.MIN_PRIORITY);
   }
   @Override
   public void run(){
      while(true){      
         try{
            sleep(1000);// every sec
        }catch (InterruptedException e){
            e.printStackTrace();
         }
//Start.Game_Thread my main Procces Thread
        if(!Start.Game_Thread.isAlive()){
/*finalize_Ap(){
etc(); // my case stop server client - send exit packets
System.Exit(0);
}*/

               Start.finalize_Ap();
         }
      }
   }
}


Offline Regenuluz
« Reply #1 - Posted 2013-04-12 18:28:04 »

I have no idea what your question is, or what your problem is, but I'm guessing that you forgot to do

1  
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


on your JFrame. That'll close the app, once the window closes.
Offline DQQAYME

Junior Member


Medals: 1
Projects: 1



« Reply #2 - Posted 2013-04-12 18:40:53 »

I have no idea what your question is, or what your problem is, but I'm guessing that you forgot to do

1  
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


on your JFrame. That'll close the app, once the window closes.
Not really what I am talking about Wink

And what if You have custom Process Thread that handle player actions etc..
And game in fullscrean mode or setUndecorated(true);  
you simple don’t have “X” button to close window
and all game action stopped because Main Process Thread fishised
so you cant exit simple way only Use try{} block,
to catch Exception in Thread and then finish Process.

Update:
In my case I Have 2 Threads: 1 Procces(not daemon) and 2 Client(daemon),
so you think if main thread(Procces) stops - Application will be closed,
But no - Thread AWT-EventQueue don’t give you close Application.
I don’t find way to make Thread AWT-EventQueue Daemon.

And I cant use try{} because I need debug problem,
That’s why I create “Close” Thread ^^


p.s it is difficult to understand this problem until you meet the problem themselves Wink

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2013-04-13 12:04:33 »

You got exception. What is it?

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!