CodeGym /Java Course /New Java Syntax /Multiple tasks about multi-catch

Multiple tasks about multi-catch

New Java Syntax
Level 15 , 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."

15
Task
New Java Syntax, level 15, lesson 8
Locked
Exceptions
The method throws two exceptions that inherit Exception, and two exceptions that inherit RuntimeException: NullPointerException, ArithmeticException, FileNotFoundException, URISyntaxException. You need to catch NullPointerException and FileNotFoundException, but not catch an ArithmeticException or
15
Task
New Java Syntax, level 15, lesson 8
Locked
Catching a group of exceptions
1. There are three exceptions that successively inherit Exception. 2. The Exception1 class extends Exception 3. The Exception2 class extends Exception1 4. The Exception3 class extends Exception2 5. There is a method with the following signature: public static void method1() throws Exception1, Except
15
Task
New Java Syntax, level 15, lesson 8
Locked
Catching checked exceptions
In the handleExceptions method, handle all checked exceptions. You need to display the checked exception that occurs. You can only use one try-catch block
15
Task
New Java Syntax, level 15, lesson 8
Locked
Catching unchecked exceptions
In the handleExceptions method, handle all unchecked exceptions. You need to use the printStack method to display the stack trace of the exception that occurs. You can only use one try-catch block
15
Task
New Java Syntax, level 15, lesson 8
Locked
Catching custom exceptions
1. Analyze the exceptions thrown by the BEAN.throwExceptions method. 2. In the handleExceptions method, call the BEAN.throwExceptions method and handle the exceptions: 2.1. if there is a FileSystemException, then log it (call the BEAN.log method) and rethrow 2.2. if there is a CharConversionExceptio
15
Task
New Java Syntax, level 15, lesson 8
Locked
Creating your own exceptions
There are four classes: MyException, MyException2, MyException3, and MyException4. Inherit the classes so that you get any two checked exceptions and any two unchecked exceptions.
Comments (47)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Michael Amann Level 22, United States of America, United States
15 May 2022
I smoked this section!
Anonymous #10960894 Level 19, Arnold, United Kingdom
31 March 2022
Am I missing something here: In catching checked exceptions, part of the task is "The handleExceptions method should catch and display all the exceptions that occur." The code throws three different types of exception in three modules, the accepted solution only catches two. Why is RemoteException ignored?
Andrés Sebastián López Level 10, San Francisco, SL, Argentina
11 October 2022
I don't know if I am right, but RMI is for Remote Method Invocation, and that means an exception can be thrwon from a remote virtual machine. So, what I understand -and just a little because I'm really noob- is that RemoteException would throw the other two exceptions because you are working with same solution, so other two exceptions are also caught. Again, I don't know if what I'm saying it's correct...
Jonaskinny Level 25, Redondo Beach, United States
20 February 2022
Seems a fare number of folks don't understand the Exceptions paradigm. Basically anyone can create a method that throws some exception type(s), and since we are using other classes in our methods, we need to deal with those exceptions if they do in fact get thrown. At the base of all this are the java class files, like Integer, which will do the actual work for us (i.e. divide by zero), get an error from the system (or maybe it sees the zero and pre-empts it), creates an Exception Object (in this case ArithmeticException), places it in the stack frame where the method is located that it occurred in, and forwards execution to the catch block that catches it's Exception Type (if it can) or one of it's super classes (again, if it can) and if it has no catch block for it's type or any of it's super class types, it looks to throw it up the call stack. If the method where the exception occured has 'throws xxxException' (where xxx is Arithmetic, NullPointer, etc), it will just pass it up the call chain. Using some class's method that throws an exception is instructions to us to either catch it or throw it ourselves, and on up the chain it goes. And if the method where the exception occurred does not have 'throws xxxException' and the method encountered the exception, your program halts.
Stanislav Mayer Level 15, Czech Republic
6 February 2022
I find the instructions for the last task (We're all friends here, even the exceptions) extremely confusing. And the "Hint" makes it even worse.
whoseunassailable Level 28, India, India
2 February 2022
This was nice tbh. A little bit refreshing, not too hard, not too shabby as well as seems relevant to the course. Learnt a lot and this might definitely be useful in the near future.
Anonymous #10775689 Level 14, United Kingdom
2 August 2021
I enjoyed the course much more today than yesterday. The reason is that I read the relevant Head First Java chapter first. I think this course needs some complementary reading to help make sense of what's going on. If you have the chance to read Head First or a similar Java basics book, I think you'll find it helpful too.
Stanislav Mayer Level 15, Czech Republic
6 February 2022
I apply quite an opposite approach: CodeGym learning first, then (if needed) Head First. And it works for me very well. Everyone needs to find what suits them the best, I guess. Nevertheless, it is very nice of CodeGym team that they recommended studying the Head First in 1-9 Chapter already!
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 29, 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...