How can you catch an exception thrown by another thread in Java

0 votes
Can  I get the explanation with the help of code
Dec 3, 2018 in Java by Neha
• 6,300 points
18,066 views
Young Heaven - Naked Teens & Young Porn Pictures
http://baitbus.fetlifeblog.com/?madilyn

 vanessa b porn star porn stars with huge boobs porn addiction meth machine teen porn free porn or sex stories
Best Nude Playmates & Centerfolds, Beautiful galleries daily updates
http://xxx.porn.allproblog.com/?anissa

 monica beach porn sexy athletic coed porn videos reality tv stars does porn videos penis sword fighting porn alabama porn tubes
Girls of Desire: All babes in one place, crazy, art
http://mexican.porn.bloglag.com/?jaylynn

 brittany spears flash video porn free streaming porn beta channels mature women sex porn free yong fresh pussy poron blondes porn pictures of cartoon sex porn
Nude Sex Pics, Sexy Naked Women, Hot Girls Porn
http://pornbigfatgirl.instakink.com/?marie

 lori anderson porn tubes classic porn trails free young cheerleading porn old lady porn free videos how to remove porn from computer
College Girls Porn Pics
http://free.lesbian.bestsexyblog.com/?adrianna

 ma x porn soprano porn star fievres nocturnes porn college physicals porn good free online porn yahoo answers
Hot teen pics
http://hdlesbians.relayblog.com/?armani

 video de anime porn tran porn russian porn liudmila most popular free porn websites brazilina porn
Dirty Porn Photos, daily updated galleries
http://amateurthemovie.ebonyellisemory.hoterika.com/?jaden

 young interratial porn tabelle porn porn cousin milkers porn star andi anderson bio remove porn from my computer

1 answer to this question.

0 votes

This can be done using Thread.UncaughtExceptionHandler.

Here’s a simple example:

// create our uncaught exception handler
Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() {
    public void uncaughtException(Thread th, Throwable ex) {
        System.out.println("Uncaught exception: " + ex);
    }
};

// create another thread
Thread otherThread = new Thread() {
    public void run() {
        System.out.println("Sleeping ...");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            System.out.println("Interrupted.");
        }
        System.out.println("Throwing exception ...");
        throw new RuntimeException();
    }
};

// set our uncaught exception handler as the one to be used when the new thread
// throws an uncaught exception
otherThread.setUncaughtExceptionHandler(handler);

// start the other thread - our uncaught exception handler will be invoked when
// the other thread throws an uncaught exception
otherThread.start();
answered Dec 3, 2018 by Frankie
• 9,830 points

Related Questions In Java

0 votes
1 answer

I am learning looping statements. Can you tell me how 'for-each' works in Java?

While programming we often write code that ...READ MORE

answered Apr 17, 2018 in Java by Rishabh
• 3,620 points
329 views
0 votes
3 answers

How can I add new elements to an Array in Java

String[] source = new String[] { "a", ...READ MORE

answered Sep 19, 2018 in Java by Sushmita
• 6,900 points
791 views
0 votes
2 answers
0 votes
1 answer

How can I Sort an ArrayList in Java

You can sort the ArrayList in 2 ...READ MORE

answered Apr 23, 2018 in Java by sharth
• 3,350 points
364 views
0 votes
1 answer

difference between wait() and sleep() in java

We can find a big difference between ...READ MORE

answered Apr 26, 2018 in Java by developer_1
• 3,310 points
340 views
0 votes
1 answer

What is the difference between Runnable and extends Thread

Runnable is the preferred way to create ...READ MORE

answered May 1, 2018 in Java by sharth
• 3,350 points
571 views
0 votes
1 answer

What is ArrayIndexOutOfBoundsException ?

If You check System.out.print(names.length); you will get 3 ...READ MORE

answered May 11, 2018 in Java by sharth
• 3,350 points
318 views
0 votes
1 answer

How to retrieve current stack trace?

Yes, in Java we do have a ...READ MORE

answered May 17, 2018 in Java by code.reaper12
• 3,500 points
1,168 views
0 votes
1 answer

What do you mean by aggregation in Java?

Aggregation is a specialized form of Association ...READ MORE

answered Feb 18, 2019 in Java by Frankie
• 9,830 points
244 views
0 votes
1 answer

How to create a temporary directory/folder in java?

If you are using JDK 7 use ...READ MORE

answered Aug 28, 2018 in Java by Frankie
• 9,830 points
5,604 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP