exception

Try with Resources in Java

Introduction: The try-with-resources statement introduces in Java 7 is a try statement that declares one or more resources.A resource is an object that must be closed after the program is finished with it.The try-with-resources statement ensures that each resource is closed at the end of the statement.Any object that implements java.lang.AutoCloseable interface, which includes all objects which implement java.io.Closeable,can be used as a resource. see the below sample code:- Note: More than two resources can be added separated by a…

0
Read More

Restart a thread Using UncaughtExceptionHandler

There is always a scenario in a development process where a piece of any code/line (e.g.,business logic) throws some unchecked/runtime exception which is not possible to handle as we are not sure about the user input. In that case the thread responsible for executing that piece of code dies off and the assigned task remain unfinished. Due to this the output may not be consistent and the reuslt can be pretty random. Let us take the below example, To overcome…

0
Read More