0% found this document useful (0 votes)
1 views

Java Exceptions

Uploaded by

rajibkumar10101
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)
1 views

Java Exceptions

Uploaded by

rajibkumar10101
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/ 6

‭Here’s a list of common Java exceptions along with examples for each:‬

‭Checked Exceptions‬

C throws‬
‭ hecked exceptions must be handled (using try-catch or declared using‬‭ ‭) during‬
‭compile-time.‬

I‭OException‬
‭Raised when an I/O operation fails or is interrupted.‬

‭Example:‬

‭ QLException‬
S
‭Raised when a database access error occurs.‬
‭Example:‬

import java.sql.*;‬

public class SQLExceptionExample {‬

public static void main(String[] args) {‬

try {‬

Connection conn =‬

DriverManager.getConnection("invalid_url", "user", "password");‬

} catch (SQLException e) {‬

System.out.println("Database error: " + e.getMessage());‬

}‬

}‬

}‬

‭ lassNotFoundException‬
C
‭Raised when a class cannot be found at runtime.‬
‭Example:‬

‭Unchecked Exceptions‬

‭Unchecked exceptions are not required to be declared or handled during compile-time.‬

‭ ullPointerException‬
N
null‬
‭Raised when trying to access an object that is‬‭ ‭.‬
‭Example:‬
‭java‬
‭ rrayIndexOutOfBoundsException‬
A
‭Raised when accessing an invalid index of an array.‬
‭Example:‬

‭ rithmeticException‬
A
‭Raised when an illegal arithmetic operation occurs, such as division by zero.‬
‭Example:‬
‭j‬
‭ umberFormatException‬
N
‭Raised when attempting to convert an invalid string to a number.‬
‭Example:‬

I‭llegalArgumentException‬
‭Raised when an illegal argument is passed to a method.‬
‭Example:‬
‭Errors (Rare and Serious Issues)‬

‭Errors are generally unrecoverable and should not be caught.‬

‭ utOfMemoryError‬
O
‭Raised when the JVM runs out of memory.‬
‭Example:‬

‭ tackOverflowError‬
S
‭Raised when the call stack overflows, usually due to deep or infinite recursion.‬
‭Example:‬

‭ his list covers commonly encountered exceptions. Let me know if you need examples for‬
T
‭more specific scenarios!‬

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