Wait and see

  • 14
  • Locked
All exceptions that occur while the Solution thread is running must be handled by one of these options: 1. If it's an Error, then display "Can't keep running". 2. If it's an Exception, then display "Needs handling". 3. If it's a Throwable, then display "Wait and see". Implement this logic.
You can't complete this task, because you're not signed in.
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Justin Smith
Level 38 , Greenfield, USA, United States
19 January 2022, 20:59
Hidden condition: The messages are meant to be exclusive of each other. In other words, only one message should ever be displayed. For example, e is always a Throwable (per method definition), which would imply based on the stated conditions that it should show the message for a Throwable regardless of whether or not e is also an Error or Exception. Only looking at the solution made this requirement clear.
Adrian
Level 27 , Spanish Town, Jamaica
20 January 2022, 00:51
so funny story, I just solved this task, read up on throwable and saw that Exception and Error are subclasses, realized I could use the isinstanceof operator, but my code wouldn't verify. turns out it's because I had an "if" instead of "else if" my issue is, while e is always a throwable, it is not an instance of either of its subclasses, so I can't see it being possible for more than one output to get printed
4 April 2021, 13:35
When I used currentThread() to set exception handler, it didn't work for me. So, I had to use this instead.