An exception is an unwanted condition that arises during the execution of a program.An exception can occur for many different reasons.Some reasons are:
All exception classes are sub types of the java.lang.Exception class. The exception class is a subclass of the Throwable class. During the program execution if any error occurs and you want to print your own message then you write the part of the program which generate the error in thetry{} block and catch the errors using catch() block.The syntax is:
try
{
}
catch(ExceptionName obj)
{
}
There are three types of exceptions in Java. These are -:
1. Compile time Exceptions.
2. Logical Exceptions.
3. Runtime exception.
Two types of exception functions used in java:
Java Built in exceptions: Java built functions are those function that are in java.lang class.For ex:
ArithmeticException: Arithmetic error, such as divide-by-zero.
ArrayIndexOutOfBoundsException: Array index is out-of-bounds.
User defined exceptions:It can be achieved by inheriting the root exception class.
- When the user has entered invalid data.
- When a file that needs to be opened cannot be found.
All exception classes are sub types of the java.lang.Exception class. The exception class is a subclass of the Throwable class. During the program execution if any error occurs and you want to print your own message then you write the part of the program which generate the error in thetry{} block and catch the errors using catch() block.The syntax is:
try
{
}
catch(ExceptionName obj)
{
}
There are three types of exceptions in Java. These are -:
1. Compile time Exceptions.
2. Logical Exceptions.
3. Runtime exception.
Two types of exception functions used in java:
Java Built in exceptions: Java built functions are those function that are in java.lang class.For ex:
ArithmeticException: Arithmetic error, such as divide-by-zero.
ArrayIndexOutOfBoundsException: Array index is out-of-bounds.
User defined exceptions:It can be achieved by inheriting the root exception class.
No comments:
Post a Comment