Exception Handling
Practice
2.2 (22 votes)
Basic programming
Basics of implementation
Easy
Exception handling
Implementation
Java
Problem
83% Success 3155 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a piece of Java code. You have to complete the code by writing down the handlers for exceptions thrown by the code. The exceptions the code may throw along with the handler message are listed below:

Division by zero: Print "Invalid division".
String parsed to a numeric variable : Print "Format mismatch".
Accessing an invalid index in string : Print "Index is invalid".
Accessing an invalid index in array : Print "Array index is invalid".

MyException : This is a user defined Exception which you need to create. It takes a parameter \(param\). When an exception of this class is encountered, the handler should print "MyException[param]", here \(param\) is the parameter passed to the exception class.

Exceptions other than mentioned above : Any other exception except the above ones fall in this category. Print "Exception encountered".

Finally, after the exception is handled, print "Exception Handling Completed".

Example: For an exception of MyException class if the parameter value is 5, the message will look like
MyException[5].

Input Format:
The code handles all the input itself.

Output Format:
If any exception is encountered in the code, print the respective handler code.
The last line of output should be "Exception Handling Completed".

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
97 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyGreedy AlgorithmsImplementation
Points:20
94 votes
Tags:
MathematicsOpenApprovedEasy
Points:30
2 votes
Tags:
MediumPrime FactorizationMathematicsOpenApprovedFactorization