pie154
pie154

Reputation: 613

Imageiio can't create imageinput stream

When using imageio.imageio.read iget a can't create ImageInputStream. I have a catch exception around it so the program survives but i was wondering if theres a way to put an if statement round it that checks to see if it falied and then attempt to read it again if it did. basically asking if there is a test for exceptions?

Upvotes: 1

Views: 528

Answers (1)

Carl Smotricz
Carl Smotricz

Reputation: 67760

try...catch is the test for exceptions. If you really want to treat your exception as a loop control mechanism, you can wrap it up something like this:

boolean success = false;
do {
   try {
      // do imageIO stuff
      success = true;      // this statement only reached if no exception
   } catch (Exception e) {
      System.err.println(e);
   }
} while (!success);

As doublep hints, this is a pretty senseless implementation because it's unlikely for the problem to go away from one iteration of the loop to the next, so your program will probably just loop endlessly printing error messages.

Upvotes: 1

Related Questions