Site icon WebArtDeveloper

How to Create a Custom Exception and Handle Exception with it in Core Java

In this tutorial how to create a Custom Exception and Handle Exception with it in Core Java  is shown.

Code:

ExceptionDemo1.java

class MyException extends Exception
{
MyException()
{
try
{
for(int i=0;i<5;i++)
{
if(i==3)
throw new Exception();
else
System.out.println(“i= “+i);
}
}
catch(Exception e)
{
System.out.println(“Exception raised”);
}
finally
{
System.out.println(“finally is called”);
}
}
}

class ExceptionDemo1
{
public static void main(String[] args)
{
MyException ex=new MyException();
}
}

https://youtu.be/kIGZ5GQXL8o

Exit mobile version