Posts

Showing posts with the label Exception

Changing the Default Terminal to Terminator on Ubuntu

Image
Terminator is a powerful tool for developers, allowing you to manage multiple terminal sessions in a single window. Features like splitting panes, tabs, and simultaneous input can significantly boost your productivity. Step 1: Install Terminator First, install Terminator using the apt package manager. sudo apt update sudo apt install terminator -y The -y option automatically answers 'yes' to any prompts during the installation process, streamlining the setup. Step 2: Set as the System Default Ubuntu uses a utility called update-alternatives to manage default applications. We'll use this tool to change the default terminal emulator ( x-terminal-emulator ) to Terminator. Run the Configuration Command Enter the following command in your terminal. A list of available terminals will appear. sudo update-alternatives --config x-terminal-emulator Select Terminator From the resulting list, enter the selection number corresponding to terminator and press Enter. ...

Java Exception Hierarchy – Throwable, Exception, and Error

Image
Java provides a robust and predictable error-handling system, and at the heart of this system lies the exception hierarchy rooted in the Throwable class. Understanding this hierarchy gives you several advantages: Write cleaner and safer code Respond appropriately and recover from errors Easier debugging and maintenance Build more reliable programs In this article, we’ll visualize the Java exception hierarchy, explain each layer, and cover practical exception handling strategies and best practices you’ll use every day. Java Exception Hierarchy at a Glance 1. Top-Level Class: Throwable At the very top is the Throwable class, which represents anything that can be thrown as an error or exception. It has two main direct subclasses: Error : Serious problems at the JVM or system level (not recoverable) Exception : Application-level issues (recoverable) 2. Error – System/JVM-Level Critical Failures Error represents severe problems that applications should not try ...

How Modern Java Improves Exception Handling (Java 21)

Image
In recent Java releases, especially Java 21, exception handling mechanisms have been significantly enhanced to improve both code safety and system reliability . These improvements help developers write more robust, maintainable, and error-resilient applications. 1. switch Statements Now Handle null and Support Pattern Matching In Java versions prior to 21, passing a null value to a switch statement would throw a NullPointerException . Java 21 allows developers to explicitly handle null values inside switch , preventing unexpected crashes. switch (input) { case null -> System.out.println("Input is null."); case "YES" -> System.out.println("Yes!"); default -> System.out.println("Other input."); } Benefits Prevents NullPointerException by design Improves clarity and readability 2. Pattern Matching and when Clauses in switch Java 21 introduces pattern matching for switch , allowing developers to write m...