Here is the listing of Java programming examples on Exception Handling.
1. Java Examples on Handling Exception
Exception handling is a mechanism to handle the runtime errors so that normal flow of the application can be maintained. Java exception classes are organised into a hierarchy. Exception object is an instance of an exception class. It gets created and handed to the Java runtime when an exceptional event occurred. Chained exception feature allows you to associate another exception. Checked exception is a type of exception that must be either caught or declared in the method in which it is thrown. This section contains Java programs on handling exception hierarchies, exception methods, runtime exceptions, handling empty stack exception, handling chained exception, handling multiple exceptions and super class methods.
Java Program to Use Handle the Exception Hierarchies
Java Program to Use Handle the Exception Methods
Java Program to Use Handle the Runtime Exceptions
Java Program to Use Handle the Empty Stack Exception
Java Program to Use Catch to Handle the Exception
Java Program to Use Catch to Handle Chained Exception
Java Program to Use Handle the Exception With Overloaded Methods
Java Program to Handle the Checked Exceptions
Java Program to Handle Multiple Exceptions (Divide by Zero)
Java Program to Handle Multiple Exceptions (Array Out of Bound)
Java Program to Handle Exception In a Super Class Methods
2. Java Examples on Built-in Exceptions
Built-in exceptions in java are categorized on the basis of whether the exception is handled by the java Compiler or not. There are two types of categories they are checked exceptions and unchecked exceptions. Checked Exceptions are the invalid conditions that occur in a java program due to invalid user input. Various checked exceptions are,
ClassNotFoundException, CloneNotSupportedException, IllegalAccessException, InstantiationException, InterruptedException etc. Unchecked exceptions are the run-time errors that occur because of programming errors. Various Unchecked Exceptions are, ArithmeticException, ArrayIndexOutOfBoundsException, ArrayStoreException, ClassCastException, IllegalArgumentException, IllegalMonitorStateException etc. This section contains Java programs on handling checked and unchecked exceptions.
Java Program to Handle Class Not Found Exception
Java Program to Handle Arithmetic Exception
Java Program to Handle Array IndexOutOfBoundException
Java Program to Handle NegativeArraySizeException
Java Program to Handle CloneNotSuportException
Java Program to Handle InstancetionException
Java Program to Handle IllegalArgumentException
Java Program to Class CastException
Java Program to NumberFormatException
Java Program to Handle FileNotFoundException
Java Program to Handle IOException
Java Program to Handle SQLException
3. Java Examples on Try, Catch and Finally Blocks
Try block contains set of statements where an exception can occur. Try block must be followed by catch blocks or finally block or both. catch block is used to handle the exceptions. A single try block can have multiple catch blocks. Finally block contains all the crucial statements that must be executed whether exception occurs or not. This section contains Java programs on try blocks, catch blocks, finally blocks, resources, use of catching exceptions, using try and catch for exception handling, difference between finally blocks and finalize method.
Java Program to Handle the Exception Using Try and Multiple Catch Block
Java Program to Illustrate Multiple Try and Catch Blocks
Java Program to IllustrateTry, Catch and Finally Blocks
Java Program Illustrate Nested Try, Catch and Finally Blocks
Java Program How to Terminate Finally Blocks
Java Program to Use Try With Resouces
Java Program to Use Finally Block for Catching Exceptions
Java Program to Use Try and Catch for Exception Handling
Java Program to Show Difference Between Finally Blocks and Finalize Method
Java Program to Check Value Returned to Caller if Statement from the Finally Block will Throw the Exception is Not Handle
4. Java Examples on Nested Try Statements
Try block within a try block is known as nested try block. The Java programs in this section deals with the implementation of nested try statements.
Java Program that Implement the Nested Try Statements
Java Program to Implement the Nested Try Statements
5. Java Examples on Throws
Throw KeyWord is used to explicitly throw an exception from a method or any block of code. This section contains Java programs on handling exception through throw and throws keyword. throwing the exceptions like NegativeNumberException, LessThanTenException, exception for negative array size, exception for loaded class and type checking.
Java Program to Handle the User Defined Exception Using Throw Keyword
Java Program to Handle Exception Using Throw KeyWord
Java Program to Handle Exception Using Throws KeyWord
Java Program to Pass Arguments While Throwing Checked Exception
Java Program to Throw the NegativeNumberException
Java Program to Throw the LessThanTenException
Java Program to Throw the Exception for Negative Array Size
Java Program to Throw the Exception for Loaded Class
Java Program to Rethrow Exception With Improved Type Checking
6. Java Examples on Threads and Multiple Exception Types
Thread class provide constructors and methods to create and perform operations on a thread. Handling more than one type of exception is called multiple exception. This section contains Java programs on exceptions with thread, catching multiple exception types, illustrate use of overloading, printing stack of the exception and printStackTrace exception.
Java Program to Use Exceptions with Thread
Java Program to Catch Multiple Exception Types
Java Program to Illustrate Use of Overloading
Java Program to Print Stack of the Exception
Java Program to Use printStackTrace in Exception
7. Java Examples on Checked & Unchecked Exception
Checked Exceptions are the invalid conditions that occur in a java program due to invalid user input. Unchecked exceptions are the run-time errors that occur because of programming errors. Create own exception class and throw that exception using throw keyword is called user-defined exceptions. Displaying the sum of integer values using exception.
Java Program to Check if Given Exception is Unchecked Exception
Java Program to Check if Given Exception is Checked Exception
Java Program to Display the Sum of Integer Value Using Exception
Java Program to Handle Custom Exception or User Defined Exception
Java Program to Create User Defined Exception
8. Java Examples on Bank Applications
This section contains Java programs to create an bank account with minimum balance, deposit amount, withdraw amount and throws LessBalanceException, create a LessBalanceException class which returns a statement says withdraw amount is not valid, creates 2 accounts and try to withdraw more money than account and see which type of exception occurs.
Java Program to Create Account with 500 Rs Minimum Balance, Deposit Amount, Withdraw Amount and Also Throws LessBalanceException.
Java Program Which has a Class Called LessBalanceException Which returns the Statement that Says WithDraw Amount(_Rs) is Not Valid
Java Program that has a Class Which Creates 2 Accounts, Both Account Deposite Money and One Account Tries to WithDraw more Money Which Generates a LessBalanceException Take Appropriate Action for the Same