diff options
author | Kevin Rushforth <[email protected]> | 2005-11-09 23:56:17 +0000 |
---|---|---|
committer | Kevin Rushforth <[email protected]> | 2005-11-09 23:56:17 +0000 |
commit | 0878e0e6691120b1e17957a9c0090d913ad3d2f7 (patch) | |
tree | 29031ce8f424b3611018c57a8ee0923d7450917a | |
parent | c7cfa6143c8bf20068cfbd58b59122b3143c45c9 (diff) |
Fixes for the following two issues:
Issue 169 : TextureLoader should throw an exception instead of printing cryptic message to System.err
Issue 170 : TextureLoader should throw exception when loading image
git-svn-id: https://svn.java.net/svn/j3d-core-utils~svn/trunk@86 9497e636-51bd-65ba-982d-a4982e1767a5
-rw-r--r-- | src/classes/share/com/sun/j3d/utils/image/ImageException.java | 66 | ||||
-rw-r--r-- | src/classes/share/com/sun/j3d/utils/image/TextureLoader.java | 14 |
2 files changed, 74 insertions, 6 deletions
diff --git a/src/classes/share/com/sun/j3d/utils/image/ImageException.java b/src/classes/share/com/sun/j3d/utils/image/ImageException.java new file mode 100644 index 0000000..b17b73c --- /dev/null +++ b/src/classes/share/com/sun/j3d/utils/image/ImageException.java @@ -0,0 +1,66 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package com.sun.j3d.utils.image; + + +/** + * Exception used to indicate that the texture loader encountered + * a problem loading the specified image file. + */ +public class ImageException extends RuntimeException { + + public ImageException() { + super(); + } + + public ImageException(String s) { + super(s); + } + + public ImageException(Throwable t) { + super(t); + } +} + diff --git a/src/classes/share/com/sun/j3d/utils/image/TextureLoader.java b/src/classes/share/com/sun/j3d/utils/image/TextureLoader.java index edae02f..3edc5cf 100644 --- a/src/classes/share/com/sun/j3d/utils/image/TextureLoader.java +++ b/src/classes/share/com/sun/j3d/utils/image/TextureLoader.java @@ -257,6 +257,8 @@ public class TextureLoader extends Object { * @param format The format specifies which channels to use * @param flags The flags specify what options to use in texture loading (generate mipmap etc) * @param observer The associated image observer + * + * @exception ImageException if there is a problem reading the image */ public TextureLoader(final String fname, String format, int flags, Component observer) { @@ -272,8 +274,7 @@ public class TextureLoader extends Object { try { return ImageIO.read(new File(fname)); } catch (IOException e) { - System.err.println(e); - return null; + throw new ImageException(e); } } } @@ -283,7 +284,7 @@ public class TextureLoader extends Object { this.flags = flags; if (bufferedImage==null) { - System.err.println("Error loading Image "+fname ); + throw new ImageException("Error loading image: " + fname); } if ((flags & BY_REFERENCE) != 0) { @@ -332,6 +333,8 @@ public class TextureLoader extends Object { * @param format The format specifies which channels to use * @param flags The flags specify what options to use in texture loading (generate mipmap etc) * @param observer The associated image observer + * + * @exception ImageException if there is a problem reading the image */ public TextureLoader(final URL url, String format, int flags, Component observer) { @@ -347,8 +350,7 @@ public class TextureLoader extends Object { try { return ImageIO.read(url); } catch (IOException e) { - System.err.println(e); - return null; + throw new ImageException(e); } } } @@ -358,7 +360,7 @@ public class TextureLoader extends Object { this.flags = flags; if (bufferedImage==null) { - System.err.println("Error loading Image "+url.toString() ); + throw new ImageException("Error loading image: " + url.toString()); } if ((flags & BY_REFERENCE) != 0) { |