Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I ignore an exception?

Tags:

scala

Is there more elegant way to write the following?

try {     ... // Some throwing code     return first }  catch {     case e:ExceptionType => {} // No code to execute. Ignore error. } return second 
like image 759
Basilevs Avatar asked Oct 18 '10 14:10

Basilevs


People also ask

How do I ignore exception?

To ignore an exception in Java, you need to add the try... catch block to the code that can throw an exception, but you don't need to write anything inside the catch block.

How do I ignore NullPointerException?

How to avoid the NullPointerException? To avoid the NullPointerException, we must ensure that all the objects are initialized properly, before you use them. When we declare a reference variable, we must verify that object is not null, before we request a method or a field from the objects.

Which keyword is used to ignore the exception from any method?

In the catch block you can mention the exception and ignore keyword for that exception.

How do you stop an exception in Java?

The try-catch is the simplest method of handling exceptions. Put the code you want to run in the try block, and any Java exceptions that the code throws are caught by one or more catch blocks. This method will catch any type of Java exceptions that get thrown. This is the simplest mechanism for handling exceptions.


1 Answers

scala.util.control.Exception.ignoring(classOf[ExceptionType]) {   ... // Some throwing code } 
like image 65
Daniel C. Sobral Avatar answered Oct 08 '22 01:10

Daniel C. Sobral