1

Can the following code be considered as an example for custom exception? If not, can you please explain why from your point of view?

public class UseJDBC
{ 
    public useJDBC() throws Exception
    {
        throw new Exception("ABC");
    }

    public static void main(String args[])
    {
        try 
        {
            useJDBC a = new useJDBC();
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }
}
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252

1 Answers1

1

No it is not. If you want to create a custom exception you have to extend java.lang.Exception or one of its subclasses. See https://docs.oracle.com/javase/tutorial/essential/exceptions/creating.html

adrien v
  • 88
  • 1
  • 5