Link to home
Start Free TrialLog in
Avatar of laes_
laes_

asked on

how continuing running the daemon if one thread throws exception

i have a daemon witch have a list of thread
every thread has one task to do
and has try catch block
if a thread crashes,i want to inform in display the cause of this execption(Exeption e){e.getMessage}
and continuing running the thread in the current state without starting the daemon ,
could u help me please
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ie:

public class MyThread extends Thread
{
    // A method which sometimes throws an exception
    public int getNum( int i ) throws IllegalArgumentException
    {
        if( i == 5 )
            throw new IllegalArgumentException( "I don't like the number 5" ) ;
        return i ;
    }

    public void run()
    {
        for( int i = 0 ; i < 10 ; i++ )
        {
            try
            {
                System.out.println( "Processing " + i ) ;
            }
            catch( IllegalArgumentException ex )
            {
                System.out.println( "Caught Exception: " + ex.getMessage() ) ;
            }
        }
    }
}

then:

new MyThread().start() ;
Sorry

                System.out.println( "Processing " + i ) ;

should be

                  System.out.println( "Processing " + getNum( i ) ) ;