Debug everything under the sun

  • 18
  • Locked
Figure out what the program does. Read about UncaughtExceptionHandler - it's important. Take another careful look at the program. Figure out why our OurUncaughtExceptionHandler doesn't work (use the debugger). Fix the bug, i.e. everything should work. :) Expected result in no particular order: Thre
You can't complete this task, because you're not signed in.
Comments (13)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Jonaskinny Java Developer at Sandmedia
25 April 2022, 03:44
Good way to enforce reading docs. Sometimes I go off searching for 'the answer' when I really should read the API docs first.
Tamas Horcsak
Level 18 , Leeds, United Kingdom
31 March 2022, 22:29
wow easiest 2.57 dark matter for one letter :-)
Justin Smith
Level 38 , Greenfield, USA, United States
17 September 2021, 21:01
This task was really disappointing. It's "Hard" in the sense that you just have to google for the solution or give up and see what other people did. There's no careful strategy to making complex logic (those are fun tasks), just making a change to a single line of code. And honestly the main topic of this task (UncaughtExceptionHandler) should be it's own lesson, it seems far too important to be half-heartedly introduced this way.
Oliver Heintz
Level 18 , Mustang, United States
10 February 2021, 19:04
I don't have the slightest clue what is going on anymore. I don't even know what this task is asking me to do. Is it time to just quit trying, accept that I've failed in the pursuit of Java proficiency, and eat a bullet?
Gellert Varga
Level 23 , Szekesfehervar, Hungary
18 April 2021, 22:38
I think nothing should be too complicated. I belive if they explain something well, everything can be easily understood. But here, unfortunately, some explanations are missing. Do it yourself... I'm not saying it's impossible. But a good teacher would be a very great treasure: he/she would spare the next generation from having to rediscover everything... - If anybody ask me something, my attitude is that I like to explain everything well, in detail, in an understandable way, without skipping of steps. Sometimes I miss the same attitude from CodeGym. Here we are forced to suffer. But i think this is not the best way to learn: it's slow and inefficient. And that's why you're starting to feel like you're stupid. But you're not that.
Dan
Level 26 , Clarksville, United States
17 June 2021, 03:49
Oliver, I know you made this post a while ago, and have since advanced a few levels. Still, I want to let you know that you matter regardless of any failings that you have at learning a particular skill. As for this specific problem, I've come to realize (very very slowly) that the problem is this -- just because you have set the TestedThread class's UncaughtExceptionHandler to be "handler" which was created above, this DOES NOT mean that any standard Thread classes we create will also have their UncaughtExceptionHandler set to "handler". The way that we solve this is by either setting our DefaultUncaughtExceptionHandler to "handler" thereby making all threads created use the same handler (the one that was created for us) OR we can go to each thread (threadA, threadB) and individually set their UncaughtExceptionHandler. Hope this helps! Dan
Sela
Level 20 , Poland
8 August 2020, 05:51
TestedThread class (commonThread) has its own UncaughtExceptionHandler defined but Thread (threadA, threadB) is the other case. so using setUncaughtExceptionHandler(handler) - in contrast to setDefaultUncaughtExceptionHandler(handler) - in TestedThread will work if in main we start and then interrupt commonThread (neither threadA nor threadB)
commonThread.start();
commonThread.interrupt();
commonThread, threadA and threadB belongs to the same system ThreadGroup. using setDefaultUncaughtExceptionHandler(handler) - in contrast to setUncaughtExceptionHandler(handler) - sets the default handler for entire group. this is why it works for threadA, threadB and also commonThread
Henrique
Level 41 , São Paulo, Brazil
12 June 2020, 16:59
Will this course teach us how to use this "debugger" thing or we are going to learn it by ourselves? I have no clue what is it and how I deal with it. And I don't even know where to start...
BlueJavaBanana
Level 37
14 May 2020, 10:39
I don't want the answer to this, but I'm really struggling to grasp how to approach this problem. Has anyone got any tips/subtle hints?
Robert Constantinescu
Level 25 , Bucharest, Romania
28 November 2019, 19:29
https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.UncaughtExceptionHandler.html
public static interface Thread.UncaughtExceptionHandler
Interface for handlers invoked when a Thread abruptly terminates due to an uncaught exception. When a thread is about to terminate due to an uncaught exception the Java Virtual Machine will query the thread for its UncaughtExceptionHandler using Thread.getUncaughtExceptionHandler() and will invoke the handler's uncaughtException method, passing the thread and the exception as arguments. If a thread has not had its UncaughtExceptionHandler explicitly set, then its ThreadGroup object acts as its UncaughtExceptionHandler. If the ThreadGroup object has no special requirements for dealing with the exception, it can forward the invocation to the default uncaught exception handler.
Fadi Alsaidi
Level 34 , Carrollton, TX, USA
24 February 2020, 15:42
Although it's still hard for me to understand all the Oracle documentation, they provide the full picture. One day it will be an easy read I would hope. here is a quick summary of the above inhope it would help someone: you can change the way the un-handled exceptions get handled in Java. the default way in Java is printing out the familiar trace stack. to change the default behavior, create a class of your own that implements the Thread.UncaughtExceptionsHandler. once the class is created, override the uncaughtException method( this will let you handle any un-handled exceptions). now we need to decided weather to handle to un-handled exceptions for just a particular thread's exception, or for all threads( all threads' exceptions would mean all exceptions that are not handled): for just a particular thread: use the setUncaughtExceptionHandler( you own created class from above) ; for all un-handled exceptions: use setDefaultUncaughtExceptionHandler(you own created class from above); Hope that helps. please replay if there is something wrong with what I've said
Sela
Level 20 , Poland
8 August 2020, 05:45
thread is not an exception
Fadi Alsaidi
Level 34 , Carrollton, TX, USA
17 August 2020, 04:11
fixed