John B
John B

Reputation: 63

Is there a way I could make a try-try-catch block?

I am using Apache POI to try and read word files, but this should still be answerable even if you have worked with Apache POI. In the HWPF.extractor package there are two objects, the WordExtractor and the Word6Extractor, the text extractor for older Microsoft Word formats. I am trying to use a try catch statement to try the WordExtractor object. Then if that throws an error it should try the Word6Extractor before throwing an exception.

I have already tried this:

try{
    WordExtractor example = new WordExtractor(...);
} try{
    Word6Extractor example = new Word6Extractor(...);
} catch(Exception e)
{
    //code to alert user to bad file type
}

If there's anything else you need to know just tell me and I will try to provide it.

Upvotes: 0

Views: 98

Answers (1)

Clemson
Clemson

Reputation: 506

I think that the only thing wrong with your code is the syntax! Although using exceptions for control flow is pretty messy, and commonly it's bad coding practice (or so I've been taught), I do believe this should do the trick:

try{
  WordExtractor example = new WordExtractor(...);
} catch (Exception e){

  // If there is an exception thrown, we run the next block of code
  try 
  {
    Word6Extractor example = new Word6Extractor(...);
  } catch(Exception e)
  {
    //code to alert user to bad file type
  }

}

Hope this clears it up!

Upvotes: 1

Related Questions