Lews Therin
Lews Therin

Reputation: 10995

Throw Exception With BufferedInputStream

is there a way to throw an exception with

ImageIO.read(getClass().getResourceAsStream("images/castle.jpg")))

This solves my problem with reading images from a .jar file. But the problem is it doesn't throw an exception. It is weird that read throws an exception for

ImageIO.read(new File(getClass().getResourceAsStream("images/castle.jpg").toString()))

Is there a way? I have tried to make it work for eclipse and .jar but nothing works! And I hate to keep checking for nulls

Thanks

Upvotes: 1

Views: 656

Answers (1)

mKorbel
mKorbel

Reputation: 109823

are you meaning Exceptions ?, for example

try {
    image = ImageIO.read(YourClassName.class.getResource("resources/image.png"));
} catch (IOException ex) {
    Logger.getLogger(YourClassName.class.getName()).log(Level.SEVERE, null, ex);
}

Upvotes: 1

Related Questions