Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java exception handling

Tags:

java

exception

How do I use exceptions and exception handling to make my program continue even if an exception occurs while processing certain files in a set of files?

I want my program to work fine for correct files while for those files which cause an exception in program, it should ignore.

Regards,

magggi

like image 432
Magggi Avatar asked Sep 02 '10 09:09

Magggi


People also ask

What are the 5 keywords in Java exception handling?

The exception handling fundamentals in Java revolve around the five keywords- try, catch, finally, throw, and throws. These keywords form the base of exception handling. All the exception handling mechanisms in Java are a result of these five keywords.

What is exception in Java with example?

A Runtime error is called an Exceptions error. It is any event that interrupts the normal flow of program execution. Example for exceptions are, arithmetic exception, Nullpointer exception, Divide by zero exception, etc. Exceptions in Java are something that is out of developers control.

What are the two types of exception handling?

There are mainly two types of exceptions in Java as follows: Checked exception. Unchecked exception.


1 Answers

for(File f : files){
   try {
       process(f); // may throw various exceptions
   } catch (Exception e) {
       logger.error(e.getMessage(), e);
   }
}
like image 130
Michael Borgwardt Avatar answered Oct 03 '22 15:10

Michael Borgwardt