undefined

Multiple tasks about multi-catch

Java Syntax
Level 9 , Lesson 8
Available

"Hi, Amigo. Yesterday I was a bit tipsy, so I'm afraid I've messed up your tasks. But I hope you won’t be mad at me and will complete them all. It's for your own good. Here they come."

undefined
3
Task
Java Syntax, level 9, lesson 8
Locked
Exceptions. Just exceptions.
We have a method. It throws two exceptions that inherit Exception, and two exceptions that inherit RuntimeException: NullPointerException, ArithmeticException, FileNotFoundException, URISyntaxException. Task: catch NullPointerException and FileNotFoundException, without catching ArithmeticException or URISyntaxException. How do you do that?
undefined
3
Task
Java Syntax, level 9, lesson 8
Locked
Catching a group of exceptions
There are 3 exceptions that successively inherit Exception (Exception1 extends Exception, Exception2 extends Exception1, and Exception3 extends Exception2). In the program, you will find the public static void method1() throws Exception1, Exception2, Exception3 method. Task: write a catch block that will catch all three exceptions: Exception1, Exception2, and Exception3.
undefined
6
Task
Java Syntax, level 9, lesson 8
Locked
Catching custom exceptions
Perhaps you think multi-layered exception structures are evil and difficult. In reality, exceptions are simple and one of the most valuable parts of Java. This may be hard to believe on Level 9, but working with exceptions seems super confusing because it is still unfamiliar. Let's move forward without fear: in this task, you'll need to catch custom exceptions.
undefined
3
Task
Java Syntax, level 9, lesson 8
Locked
Catching checked exceptions
Lessons at the secret CodeGym center have taught us that if a ClassNotFoundException or FileNotFoundException are thrown (occur) in a method, then the programmer is simply obligated to indicate them in the method signature. These are checked exceptions. Let's handle them in the handleExceptions method and display them on the screen.
undefined
3
Task
Java Syntax, level 9, lesson 8
Locked
Catching unchecked exceptions
"But there's another kind of exception—the RuntimeException and the classes that inherit it. They don't have to be caught — because they're unchecked! They are a mystery. Their occurrence is hard to predict and they don't need to be indicated in the throws clause," say the CodeGym lessons. The time has come to handle all unchecked exceptions in the handleExceptions method.
undefined
3
Task
Java Syntax, level 9, lesson 8
Locked
We're all friends here, even the exceptions
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.
Comments (37)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Sinisa Level 11 Banja Luka Bosnia and Herzegovina
15 March 2021
This whole lesson is only complicating things when it comes to beginners (as advanced ones certainly do not attend classes like this one). You need try/catch when your program has multiple outcomes that can lead to abnormal program termination. So you need to catch one or multiple error messages that JVM throws back to you, or through testing predict what the possible errors may be and how to catch them. Another thing is difference between throwing/try-catching, ie. what JVM checks, what not. And that's all, on top of that you further advance your knowledge.
Jurij Thmsn Level 18 Flensburg Germany
29 January 2021
I did all the task on the first or second try but still don't feel like I understood anything :D I hope I will in the future...
David Haines Level 12 La Crosse United States
29 September 2020
I got really lucky on this one but I still don't understand it.
Lucia Level 13 Madrid Spain
25 September 2020
a little help please with the last one.. I am not sure I understand it correctly
Agent Smith Level 38
20 August 2020
"Exceptions" tasks were exceptionally easy - an interesting exception indeed.
matt Level 11 Springfield United States
13 August 2020
So in the handleExceptions method , why don't you have to put " public static void handleExceptions(Solution obj) throws Exception{ // instead of just , public static void handleExceptions(Solution obj) { I thought you had to always put throws the exception type in the method that you are doing the try catch blocks
Aakankasha Sharma Level 17 Chandigarh India
25 June 2020
Why does inheriting Exception class make it a checked exception only?
Blaise Level 20 London United Kingdom
15 May 2020
In case you use the website to complete the tasks. First task only: "This task cannot be run on the CodeGym server. Use IntelliJ IDEA."
Robert Constantinescu Level 25 Bucharest Romania
26 October 2019
Interesting how less and less students complete these tasks as you go higher with the level Consistency is the key, my friends. Just do it whether you are in the mood or not. Good Luck!
Clark Level 16 Berlin Germany
14 July 2019
Thanks CodeGym for this lesson and to all guys they helped me to solve it.