Search This Blog

Java Exceptions Catalog Part 2: Complete Guide to I/O, Filesystem & Network Errors

Java Exceptions Catalog - Part 2: I/O, Filesystem & Network Exceptions

Java Exceptions Catalog - Part 2: I/O, Filesystem & Network

Comprehensive reference guide to standard stream exceptions (java.io), modern file channels/buffers (java.nio), and network/SSL exceptions (java.net & javax.net.ssl).

1. Stream & Serialization Exceptions (java.io Package)

JAVA.IO

java.io.IOException

Base class for exceptions produced by failed or interrupted I/O operations across streams, files, and sockets.

JAVA.IO

java.io.FileNotFoundException

Attempting to access a file at a path that does not exist or cannot be opened due to permission restrictions.

Resolution
Verify file paths (relative vs. absolute) and check file existence with Files.exists(path) before opening input streams.
JAVA.IO

java.io.EOFException

Signals that an end of file or end of stream has been reached unexpectedly during an input operation.

Resolution
Ensure stream readers handle stream length bounds properly instead of expecting fixed byte counts.
JAVA.IO

java.io.NotSerializableException

Attempting to serialize an object instance that does not implement the java.io.Serializable marker interface.

Resolution
Implement Serializable on the target class or mark un-serializable fields as transient.
JAVA.IO

java.io.InvalidClassException

Serialization runtime detects a class mismatch, missing serialVersionUID, or restricted access modifiers during deserialization.

Resolution
Explicitly declare a fixed private static final long serialVersionUID across versions.
JAVA.IO

java.io.InterruptedIOException

Signals that an I/O operation has been interrupted by another thread.

JAVA.IO

java.io.StreamCorruptedException

Control information read from an object input stream violates internal consistency checks.

JAVA.IO

java.io.OptionalDataException

Object read operation failed because primitive data was encountered instead of an object in the stream.

JAVA.IO

java.io.WriteAbortedException

Reading an object stream interrupted because one of the inner objects threw an exception during writing.

JAVA.IO

java.io.SyncFailedException

Signaled when a FileDescriptor.sync() system call fails to flush buffers to underlying physical media.

JAVA.IO

java.io.CharConversionException

An error occurred during character encoding or decoding operations.

JAVA.IO

java.io.UTFDataFormatException

A malformed modified UTF-8 string was encountered in a data input stream.

JAVA.IO

java.io.UncheckedIOException

An unchecked wrapper exception around an IOException (commonly thrown during Java Stream API pipelines).

2. Filesystem, Channels & Buffers (java.nio Package)

JAVA.NIO

java.nio.file.FileSystemException

Base class for file system operation failures in the modern NIO.2 API.

JAVA.NIO

java.nio.file.NoSuchFileException

Thrown when an NIO file system operation fails because a target file or directory path does not exist.

Resolution
Use Files.exists(path) or Files.createDirectories(path) before executing operations.
JAVA.NIO

java.nio.file.AccessDeniedException

File operation fails due to insufficient file permissions or OS access restrictions.

Resolution
Check OS level read/write permissions or adjust POSIX file permissions using Files.setPosixFilePermissions().
JAVA.NIO

java.nio.file.FileAlreadyExistsException

Attempting to create a file or directory at a path that already exists on disk.

JAVA.NIO

java.nio.file.DirectoryNotEmptyException

Attempting to delete a directory that still contains files or subdirectories.

JAVA.NIO

java.nio.file.AtomicMoveNotSupportedException

Attempting an atomic move file operation across different mounted filesystems.

JAVA.NIO

java.nio.channels.ClosedChannelException

Attempting an I/O operation on an NIO Channel that has already been closed.

Resolution
Check channel state with channel.isOpen() prior to performing read or write calls.
JAVA.NIO

java.nio.channels.AsynchronousCloseException

Operation interrupted because another thread closed the underlying channel instance.

JAVA.NIO

java.nio.channels.ClosedByInterruptException

Channel closed automatically because the thread executing the I/O call was interrupted.

JAVA.NIO

java.nio.channels.OverlappingFileLockException

Attempting to acquire a file lock that overlaps an existing lock held by the same JVM instance.

JAVA.NIO

java.nio.channels.NonReadableChannelException

Attempting to read from an NIO channel that was opened without read access permissions.

JAVA.NIO

java.nio.channels.NonWritableChannelException

Attempting to write to an NIO channel that was opened without write access permissions.

JAVA.NIO

java.nio.BufferOverflowException

Writing elements into an NIO Buffer past its defined limit capacity.

JAVA.NIO

java.nio.BufferUnderflowException

Reading elements from an NIO Buffer when fewer elements remain than requested.

JAVA.NIO

java.nio.InvalidMarkException

Attempting to call buffer.reset() without previously defining a valid mark position.

JAVA.NIO

java.nio.ReadOnlyBufferException

Invoking mutation methods (like `put()`) on a read-only NIO Buffer.

3. Networking, Sockets & SSL (java.net & javax.net.ssl Package)

JAVA.NET

java.net.SocketException

Base class for underlying TCP/UDP socket creation or protocol transmission errors.

JAVA.NET

java.net.ConnectException

Connection refused by remote host on specified address/port (service down or port closed).

Resolution
Verify target server host and port. Ensure process is running and firewall rules allow traffic.
JAVA.NET

java.net.SocketTimeoutException

A timeout occurred on socket read or connect before receiving data from remote host.

Resolution
Increase read timeout values via socket.setSoTimeout(ms) or optimize remote server latency.
JAVA.NET

java.net.UnknownHostException

The IP address of a host could not be resolved by DNS or local network lookups.

Resolution
Check hostname string for typos, verify active internet connection, and validate DNS settings.
JAVA.NET

java.net.BindException

Attempting to bind a socket to a local address/port that is already in use by another process.

JAVA.NET

java.net.NoRouteToHostException

Remote host unreachable due to intermediate router issues or local network/firewall blocks.

JAVA.NET

java.net.PortUnreachableException

An ICMP Port Unreachable message was received on a connected UDP socket.

JAVA.NET

java.net.MalformedURLException

A URL string could not be parsed because no valid protocol was specified or the string format is corrupt.

JAVA.NET

java.net.URISyntaxException

Checked exception indicating that a string could not be parsed as a URI reference.

JAVA.NET

java.net.ProtocolException

An error occurred in the underlying protocol (e.g., HTTP protocol error).

JAVA.NET

java.net.HttpRetryException

An HTTP request cannot be retried automatically due to streaming mode restrictions.

SSL

javax.net.ssl.SSLException

Base class for errors encountered during SSL/TLS negotiation or secure communication.

SSL

javax.net.ssl.SSLHandshakeException

TLS handshake failed due to untrusted certificates, expired certificates, or cipher protocol mismatch.

Resolution
Import missing CA certificates into Java truststore (`cacerts`) using `keytool` or update TLS version configuration.
SSL

javax.net.ssl.SSLPeerUnverifiedException

Indicates that the remote peer's identity has not been verified during SSL session setup.

SSL

javax.net.ssl.SSLProtocolException

Indicates an error in the operation of the SSL protocol implementation.

No comments:

Post a Comment