java core

Your blog category

Checked vs. unchecked exceptions

Java divides exceptions into two main categories: checked and unchecked exceptions. Understanding the distinction is crucial for effective exception handling and robust application design. Feature Checked Exceptions Unchecked Exceptions Compile-Time Checking Yes – compiler enforces handling No – compiler does not require handling Inheritance Subclasses of Exception (but not RuntimeException) Subclasses of RuntimeException Handling Requirement …

Checked vs. unchecked exceptions Read More »

Creating custom exceptions

In Java, custom exceptions are user-defined exceptions that extend the built-in Exception or RuntimeException classes. They allow you to represent specific error conditions that are meaningful to your application domain, improving code clarity, maintainability, and robustness. Why Create Custom Exceptions? Domain-Specific Clarity: Standard exceptions like IOException or NullPointerException may not describe application-specific issues precisely. Custom …

Creating custom exceptions Read More »

Throwing Exceptions

In Java, throwing exceptions is an essential part of error handling, allowing you to signal that something unexpected has occurred during the execution of your program. This mechanism is used to indicate abnormal behavior and to provide control over how the program reacts to various error conditions. Key Points About Throwing Exceptions: throw keyword: The …

Throwing Exceptions Read More »

finally block

In Java, the finally block is used to execute important code such as resource cleanup, regardless of whether an exception is thrown or not. It is associated with try-catch blocks and is always executed after the try and catch blocks, even if an exception is thrown or if there is no exception. Key Features: Guaranteed …

finally block Read More »

Scroll to Top