Answer to Question #257403 in Java | JSP | JSF for Shayla

Question #257403

Write a program to create your own Exception subclass. You need to also override toString() method to define a tailor made description of your own Exception subclass. Then create a class where an exception of the created Exception subclass is thrown by using throw keyword. You need to define a try and catch block to handle the exception in the main method. Finally, after the exception is handled, print "Exception Handling Completed".

1
Expert's answer
2021-10-27T16:27:05-0400
import java.io.*;
class ExceptionHandle
{
 void display() throws Exception
  {  System.out.println("parent class");  }
}


public class Main extends ExceptionHandle {
 void display() throws Exception  
   { System.out.println("Exception handling completed "); }


 public static void main(String[] args)
 {
  try {
   ExceptionHandle s=new Main();
   s.display();
   }
  catch(Exception e){}
 }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS