//But I write the more boldly to you in part, as reminding you, because of the grace that was given to me by God (Romans 15:15) package com.javarush.task.task16.task1633; public class Solution { public static Thread.UncaughtExceptionHandler handler = new OurUncaughtExceptionHandler(); public static void main(String[] args) { TestedThread commonThread = new TestedThread(handler); Thread threadA = new Thread(commonThread, "ÐиÑÑ 1"); Thread threadB = new Thread(commonThread, "ÐиÑÑ 2"); threadA.start(); threadB.start(); threadA.interrupt(); threadB.interrupt(); } public static class TestedThread extends Thread { public TestedThread(Thread.UncaughtExceptionHandler handler) { setDefaultUncaughtExceptionHandler(handler); start(); } public void run() { try { Thread.sleep(3000); } catch (InterruptedException x) { throw new RuntimeException("My exception message"); } } } public static class OurUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { @Override public void uncaughtException(Thread t, Throwable e) { System.out.println(t.getName() + ": " + e.getMessage()); } } } /* ÐÑдебажим вÑе на ÑвеÑе РазобÑаÑÑÑÑ, ÑÑо Ð´ÐµÐ»Ð°ÐµÑ Ð¿ÑогÑамма. ÐоÑиÑаÑÑ Ð¿Ñо UncaughtExceptionHandler - ÑÑо важно. ÐÑе Ñаз внимаÑелÑно поÑмоÑÑеÑÑ Ð¿ÑогÑаммÑ. РазобÑаÑÑÑÑ - пÑодебажиÑÑ - поÑÐµÐ¼Ñ Ð½Ð°Ñ OurUncaughtExceptionHandler не ÑÑабаÑÑваеÑ. ÐÑпÑавиÑÑ Ð¾ÑибкÑ, Ñ.е. вÑе должно ÑабоÑаÑÑ. :) ÐжидаемÑй ÑезÑлÑÑÐ°Ñ Ð² пÑоизволÑном поÑÑдке: ÐиÑÑ 1: My exception message ÐиÑÑ 2: My exception message ТÑебованиÑ: 1.âÐеÑод main должен ÑоздаваÑÑ Ð½Ð¸ÑÑ Ñ Ð¿Ð°ÑамеÑÑами: commonThread и "ÐиÑÑ 1". 2.âÐеÑод main должен ÑоздаваÑÑ Ð½Ð¸ÑÑ Ñ Ð¿Ð°ÑамеÑÑами: commonThread и "ÐиÑÑ 2". 3.âÐеÑод main должен запÑÑкаÑÑ Ð´Ð²Ðµ ÑозданнÑе ниÑи Ñипа Thread. 4.âÐеÑод main должен пÑеÑÑваÑÑ Ð´Ð²Ðµ ÑозданнÑе ниÑи Ñипа Thread. 5.âÐÑогÑамма Ñ Ð¿Ð¾Ð¼Ð¾ÑÑÑ Ð¼ÐµÑода uncaughtException клаÑÑа OurUncaughtExceptionHandler должна вÑвеÑÑи 2 ÑообÑениÑ. 6.âÐеÑод uncaughtException клаÑÑа OurUncaughtExceptionHandler Ñвно не вÑзÑваÑÑ. 7.âÐÑвод пÑогÑÐ°Ð¼Ð¼Ñ Ð´Ð¾Ð»Ð¶ÐµÐ½ ÑодеÑжаÑÑ ÑÑÑоки: "ÐиÑÑ 1: My exception message" и "ÐиÑÑ 2: My exception message". package com.javarush.task.task16.task1633; public class Solution { public static Thread.UncaughtExceptionHandler handler = new OurUncaughtExceptionHandler(); public static void main(String[] args) { TestedThread commonThread = new TestedThread(handler); Thread threadA = new Thread(commonThread, "ÐиÑÑ 1"); Thread threadB = new Thread(commonThread, "ÐиÑÑ 2"); threadA.start(); threadB.start(); threadA.interrupt(); threadB.interrupt(); } public static class TestedThread extends Thread { public TestedThread(Thread.UncaughtExceptionHandler handler) { setUncaughtExceptionHandler(handler); start(); } public void run() { try { Thread.sleep(3000); } catch (InterruptedException x) { throw new RuntimeException("My exception message"); } } } public static class OurUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { @Override public void uncaughtException(Thread t, Throwable e) { System.out.println(t.getName() + ": " + e.getMessage()); } } } */