Skip to main content

Posts

Showing posts with the label handle exceptions

Handling Exceptions in Threads in Java

Introduction Exception handling is very critical to any application and any language that was used to develop. This helps the following stakeholders Stakeholders End-User: A graceful message that indicates that something has gone wrong in the system due to some wrong input or due to some internal fault Developer A clean way to get to know which line of code caused the exception and the stack trace that can help us reach to the points impacted Support Team A helpful hint that they can try to verify and resolve if it is something within their reach or to escalate to the product team SRE (Site Reliability Engineering) An indication of how far the application is performing w.r.to being reliable to the end-users and how faults are handled or tolerated etc.. Problem Statement When we use threads to get the job done for performing some intensive task (computation or Network intensive tasks), it becomes difficult to track down on the exceptions. This post is one in a series of posts that will

How to implement Global Exception Handler in Spring Boot

Exception Handling There is always a requirement to handle all the NFR (Non-Functional Requirements) well in any application so that the application performs well in production and possess the excellent traceability and exception reporting mechanisms for better visibility on what happens in applications. Types of Exceptions We normally use exceptions within each domain of the application like Customers, Orders, Inventory etc. There are also a lot of custom exceptions that might be required when the application is built to capture, report the exceptions to the user. In this process, we can follow the below given process Base Exceptions There are multiple use-cases where we need separate exceptions to report multiple error conditions or cases, let us consider one such case for data validation. BaseValidationException import java.util.List; public class BaseValidationException extends RuntimeException { public BaseValidationException() { super(); } public BaseVali