Tagged: #exceptions

ClassNotFoundException vs NoClassDefFoundError

ClassNotFoundException and NoClassDefFoundError occur when a required class is not found in the classpath at runtime. In this tutorial, we resolve the conflict between these 2 exceptions and explain the different scenarios of reproducing each one of them. 1- ClassNotFoundException As per java doc, this exception is thrown when trying to instantiate a class using one of these methods: forName(), findSystemClass(),...

Java try-with-resources

Java 7 supports a new statement called try-with-resources which extends the behavior of the traditional try/catch block for the sake of automatic resource management, since Java 7 developers are able to access resources (files, db connections, sockets) inside a try-with-resources block without the need to worry about closing them afterwards, the resource closure is done automatically. 1. Resource management using traditional...

Exception handling strategy

In this article we introduce a common strategy for handling exceptions in an OOP application, our strategy conforms to the best exception handling techniques and can be integrated in any application. 1. Overview The following diagram provides an overview of our strategy, it shows the flow of the exception starting from the detection phase until reaching the handling phase. The...

How to use exceptions effectively

Exception is an event which occurs during the execution of a program and disrupts its normal flow, it is mainly arrised from different kind of situations such as wrong user interaction, hardware failure, network failure, database failures or even business failures. 1. Checked vs Unchecked Exceptions are of 2 types: checked and unchecked. Checked exceptions are predictable during the development...