0% found this document useful (0 votes)
2 views2 pages

Java Exception Handling

Uploaded by

yogalatchoumy11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Java Exception Handling

Uploaded by

yogalatchoumy11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Exception Handling in Java

1. Error and its Types

An error is a serious issue that occurs during program execution and cannot be handled by the program.

Types of Errors:

1. Compile-time Error: Errors detected during compilation (e.g., syntax errors).

2. Run-time Error: Errors detected during execution (e.g., division by zero).

3. Logical Error: Errors due to incorrect logic (e.g., wrong formula).

2. Exception and Exception Handling

Exception: An exception is an event that disrupts the normal flow of a program.

Exception Handling: Mechanism to detect, handle, and recover from exceptions during execution without

terminating the program.

3. Types of Exceptions

a) Checked Exceptions

Handled at compile time using try-catch or throws. Example:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

b) Unchecked Exceptions

Handled at runtime. Example: int x = 10 / 0;

c) User-defined Exceptions

Custom exceptions for specific use cases. Example: class AgeException extends Exception

4. Exception Handler and its Types

Exception Handler: Block of code that handles exceptions using try, catch, finally, throw.

Types:

1. try-catch block

2. try-catch-finally block

3. Multiple catch blocks

4. Nested try-catch

5. throw keyword

6. throws keyword
Diagram: Java Exception Hierarchy

Throwable

Error Exception

Checked Exception

Unchecked Exception

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy