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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry
System.out.println( "Processing " + i ) ;
should be
System.out.println( "Processing " + getNum( i ) ) ;
System.out.println( "Processing " + i ) ;
should be
System.out.println( "Processing " + getNum( i ) ) ;
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() ;