Exception handling

Exception Handling in Java | A Beginners Guide to Java Exceptions | Edureka 

• Exception Handling is the powerful mechanism of java
• Exception is an abnormal condition occurs during run time
• Exception is an event which disrupt the normal flow of a program
• Some of the exceptions are :
      ClassNotFoundException
      SQLException
      IOException
      RemoteException

Keywords of Exception Handling

  • Try – “try” keyword is used to specify a block where do we expect    exception. Try block is followed by catch block.

• Catch - catch block is used to specify Solution of the exception raised.
It is followed by finally block.
• Finally – finally block is used to execute important code of the
program. It will execute even an exception occurs or not.
• Throw – throw keyword is used to throw an exception
• Throws – throws keyword used to declare exception and doesn’t
throw an exception.

Example

public class ExceptionExample
{
public static void main(String[] args)
{
try
{int a=12/0;}
catch(ArithmeticException ae)
{ System.out.println(ae);}
finally{System.out.println("this is finally block”);}
}
}

Example

public class ThrowDemo
{
public static void main(String[] arg) throws ArithmeticException
{
int a=12/0;
throw new ArithmeticException(“pls do correct”);
}
}

Comments

Popular posts from this blog

Unit 3 : Regression

Operating System - Unit - 4 Memory Management and File Managment

Unit 1 - Introduction to Operating Sytem & Unit 2 - Process Characterization