| 
 | 
Hm!
catching an exception is pretty easy. Give the code line which throws the 
exception into a try catch block. for example
try {
String targetFilename = imageDir + 
filename.substring(0, filename.lastIndexOf(".")) + i + ".jpg";
                                JAI.create("filestore", image, 
targetFilename, "JPEG");
}
catch(java.lang.reflect.InvocationTargetException e){
}
I think this will work, but is not best practice.
Greetings from Austria
Ralf M Petter
Shane_Cessna@xxxxxxx 
Gesendet von: java400-l-bounces@xxxxxxxxxxxx
26.09.2005 15:13
Bitte antworten an
Java Programming on and around the iSeries / AS400 
<java400-l@xxxxxxxxxxxx>
An
java400-l@xxxxxxxxxxxx
Kopie
Thema
Java Exception question...
I'm not sure if this is possible or not, but here goes.  I have a loop 
that converts multi-page TIF files to single page JPEG files...my problem 
comes when the program converts the first page of the TIF successfully 
then throws an exception 
(java.lang.reflect.InvocationTargetException)...is there any possible way 
to completely ignore this exception within my code?  I realize this might 
be taboo, but my method does what i want it to do before it hits this 
exception...here's my code:
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.image.renderable.*;
import com.sun.media.jai.codec.*;
import javax.media.jai.*;
public class Tiff2JPEG {
        public static boolean doTiff2JPEG(String filename, String 
imageDir) {
                String sourceFilename = imageDir + filename;
                try {
                        FileSeekableStream stream = new 
FileSeekableStream(sourceFilename);
                        imageDecoder dec = 
ImageCodec.createImageDecoder("tiff", stream, null);
                        int numofpages = dec.getNumPages();
                        for (i = 0; i <= numofpages; i++) {
                                RenderedImage image = 
dec.decodeAsRenderedImage(i);
                                String targetFilename = imageDir + 
filename.substring(0, filename.lastIndexOf(".")) + i + ".jpg";
                                JAI.create("filestore", image, 
targetFilename, "JPEG");        // this creates the JPG successfully, then 
throws the exception...
                        }
                return true;
                } catch (IOException e) {
                        e.printStackTrace();
                        return false;
                }
        }
 
        public static void main(String args[]) {
                if (doTiff2JPEG("multicolor14pages.tif", "C:\test 
tiffs\")) {
                        System.out.println("JPG Creation Successful!");
                } else {
                        System.out.println("JPG Creation Unsuccessful!");
                }
        }
}
Shane
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.