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 (39)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
ImDevin Level 15, Old Town, United States
9 May 2021
As others have mentioned, these tasks seemed like a marching order - just follow and do it, you might be told why's and how's later. We are still in the Syntax section, so I get we need to get used to writing them, but without more context of where and how it fits, it's easy to get discouraged. I hope CG will bring it all together in the coming levels to make sense of it all. For now, will just keep on keeping on. Happy coding! :)
Russell Level 9, Galmpton, Brixham , United Kingdom
30 April 2021
yeah i think the reason so many people stop at this point (or indeed at earlier points) is that the tasks (medium and abvove tasks) don't necessarily make any practical sense, why am I configuring an awkward ass program to collect custom exceptions. or random stack traces I need to catch exceptions in my code, yes. but why am I going out of my way to create a new one. Its just me I'm sure but i just cant see a time when application of the medium task would be at all useful. That in itself stops you in your tracks whilst you say to yourself.. "Why The F...?" Then as the code is silly to wrangle, you lose interest and thus lose interest in the course. Its a roadblock. You kind of lose trust in the tasks and thus don't complete them. Maybe they'll bring together all my knowledge later coherently
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 24, 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 13, 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 18, 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."