Moin,
gibt es eine Möglichkeit, die von der runtime geworfenen Exception (unten gekennzeichnet) das Programm nicht abstürzen zu lassen?
in der Java- API
gibt es eine Möglichkeit, die von der runtime geworfenen Exception (unten gekennzeichnet) das Programm nicht abstürzen zu lassen?
Code:
try {
baos = new ByteArrayOutputStream();
new ObjectOutputStream( baos ).writeObject( o ); // java.io.IOException: failed to load image contents
baos.flush();
bais = new ByteArrayInputStream( baos.toByteArray() );
return new ObjectInputStream(bais).readObject();
}
catch (IOException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
finally {
try {
bais.close();
baos.close();
}
catch (IOException ex) {
ex.printStackTrace();
...
in der Java- API
Code:
private void writeObject(ObjectOutputStream s)
throws IOException
{
s.defaultWriteObject();
int w = getIconWidth();
int h = getIconHeight();
int[] pixels = image != null? new int[w * h] : null;
if (image != null) {
try {
PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
pg.grabPixels();
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
throw new IOException("failed to load image contents");
}
}
catch (InterruptedException e) {
throw new IOException("image load interrupted");
}
}
s.writeInt(w);
s.writeInt(h);
s.writeObject(pixels);
}