We're all friends here, even the exceptions

  • 3
  • Locked
There was a time when exceptions kept young scientists and programmers awake at night. Today they have that effect on CodeGym students. Let's try creating our own exceptions. To do this, we have the MyException, MyException2, MyException3, and MyException4 classes. Let's have the classes inherit other classes so as to produce any two checked exceptions and any two unchecked exceptions.
You can't complete this task, because you're not signed in.
Comments (4)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
June Sung Park
Level 41 , Yangp'yong, Korea, Republic of
31 March 2020, 04:38
To give a little more hint on top of what Horst suggested, you can inherit a checked exception class such as IOException to create a class that is a checked exception, and inherit an unchecked exception class such as RuntimeException to create a class that is an unchecked exception.
Level 26 , Not in list
19 January 2020, 21:53
In case of doubt you might want to revise the article on checked and unchecked exceptions and especially what their names are...
Maxine Hammett
Level 19 , San Diego, United States
20 July 2020, 16:16
I'm still lost. Can you please explain to me how to throw the exception from an exteded class?
Level 10 , Dresden, Germany
2 September 2021, 09:18
The requirements sound like we need to do something very complicated, which led me into the wrong path of thinking. Instead of writing: 3. Two of the four classes must be checked exceptions. 4. Two of the four classes must be unchecked exceptions. codegym should have written a clearer statement of requirements like: 3. Two of the four classes must inherit checked exceptions. 4. Two of the four classes must inherit unchecked exceptions. In the end it is all pretty simple. You do not need to throw exceptions. Just let the custom classes (MyException...) inherit exception classes (checked/unchecked). Do nothing more and you meet the requirements. For example:
static class MyException4 extends ArrayIndexOutOfBoundsException