Exception Handling
Exception Handling
INTRODUCTION
An exception is an unexpected event that disrupts the normal flow of
a Java program during runtime. It represents an error condition which
can be handled by the application.
🔹 Importance of Exception Handling:
Helps in maintaining normal application flow, Improves code reliability
and readability, Facilitates debugging and error tracing, Enables
customized error messages for users.
BUILD IN SUPPORT JAVA
Java provides built-in support for exception handling through the
keywords try, catch, finally, throw, and throws, and all exceptions in
Java are derived from the Throwable class.
EAMPLE
Types of Java Exceptions
Try-Catch Block
• final: The final is the keyword that can be used for immutability and
restrictions in variables, methods, and classes.
• finally: The finally block is used in exception handling to ensure that a
certain piece of code is always executed whether an exception occurs
or not.
• finalize: finalize is a method of the object class, used for cleanup
before garbage collection.
final Keyword
• The final keyword in Java is used with variables, methods, and also
with classes to restrict modification.
• Syntax:
• // Constant value
• final int a = 100;
finalize() Method