O'Reilly logo

Instant NetBeans IDE How-to by Atul Palandurkar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling exceptions (Must know)

In this recipe, we will learn about writing and handling exceptions using NetBeans IDE.

Getting ready

Create a simple Java project to write and handle exceptions that may occur during execution, that is, at runtime, which are terminated by the JVM. This causes severe failures and the user may face a huge loss. Therefore, it is necessary to handle these exceptions.

How to do it...

The following syntax will show you how to use the try-catch blocks and handle exceptions:

try{
  // Suspected code
} catch (ExceptionType e) {
  // Necessary action code
}

To handle the exception, we can use the try-catch block, where the try block contains the code due to which an exception may occur, or the code we want to keep safe from exceptions, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required