Madhuri
Madhuri

Reputation: 197

Handle the Exception and Continue the process without termination in java

I am working on java, I read huge no.of XML files & insert them into ORACLE database but while inserting I am getting Exception, Then my program terminates without processing remaining records, Could any one please help me out from this situation, I want to read the files until unless they finished without termination of program while exception occurs.

Upvotes: 2

Views: 295

Answers (1)

jcklie
jcklie

Reputation: 4094

for (File f : myFileArray) { //Or whatever you have
   try {
       // your code which might throw exception
   } catch ( <Your exception name here> e) {
       System.err.println("File failed: " + f.getAbsoultePath() );
       continue; //if more code follows the try catch block, otherwise omit it
   }
}

Since you did not gave any code snippet for what you actually do, I tried a guess.

As the comments suggest, you use try/catch-Blocks for handling exceptions in Java.

A good tutorial is imho

http://chortle.ccsu.edu/java5/index.html

Chapter 80 and 81.

Upvotes: 3

Related Questions