Please help me code the following in JAVA 2. Handling exceptions a. b. c. d. Dow
ID: 3714091 • Letter: P
Question
Please help me code the following in JAVA
2. Handling exceptions a. b. c. d. Download the following file from the class website: CallStack.java Examine the code to determine what it does. Compile and execute the code. Modify the main0 method to handle the exception that is propagated to it. Use a try- catch block to display a meaningful error message when the exception occurs. Test your code. Notice that, although the exception was thrown in func2, it is caught by the catch block in the main method. e.Explanation / Answer
public class CallStack {
void func2() {
System.out.println("In func2 method");
int a = 0;
int b;
b=10/a;
}
void func1() {
System.out.println("In func1 method");
this.func2();
System.out.println("Back In func1 method");
}
public static void main(String args[]) {
CallStack myCallStack;
myCallStack =new CallStack();
System.out.println("In main method");
try {
myCallStack.func1();
}catch(ArithmeticException e) {
System.out.println("Exception Occurred. Divisor can not be zero");
}
}
}
Output:
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.