FOP exception
--- Received from DIST.KUOS 777-282501-12-10 16.21 - [EMAIL PROTECTED] Hi. the following is my code: //DOM import org.w3c.dom.*; import org.apache.xerces.parsers.*; //Java import java.io.*; import java.io.File; import java.lang.String; import java.net.URL; import org.apache.fop.apps.*; import org.apache.fop.messaging.*; import org.xml.sax.*; public class XMLPDF { public static void main(String[] args) { File xmlf = new File(c:/jdk1.3.1/xslfoRef.xml); File xslf = new File(c:/jdk1.3.1/xml2pdf.xsl); File writefile = new File(shu.pdf); Driver driver = new Driver(); driver.setRenderer(Driver.RENDER_PDF); InputHandler inputHandler = new XSLTInputHandler(xmlf, xslf); XMLReader parser = inputHandler.getParser(); InputSource inputSource = inputHandler.getInputSource(); driver.setOutputStream(new FileOutputStream(shu.pdf)); driver.render(parser, inputSource); //outfile.close(); } } I got the following error message: unreported exception org.apache.fop.apps.FOPException: must be caught or declared to be thrown XMLReader parser = inputHandler.getParser(); ^ it has the same error messgae for driver.setOUtputStream and driver.render. I have no idea what's wrong, plese kindly help. thanks. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: FOP exception
Hello, SHU! You wrote to [EMAIL PROTECTED] on Mon, 10 Dec 2001 12:21 -0800: Put all this code in try block. Like this try{ File xmlf = new File(c:/jdk1.3.1/xslfoRef.xml); File xslf = new File(c:/jdk1.3.1/xml2pdf.xsl); File writefile = new File(shu.pdf); Driver driver = new Driver(); driver.setRenderer(Driver.RENDER_PDF); InputHandler inputHandler = new XSLTInputHandler(xmlf, xslf); XMLReader parser = inputHandler.getParser(); InputSource inputSource = inputHandler.getInputSource(); driver.setOutputStream(new FileOutputStream(shu.pdf)); driver.render(parser, inputSource); //outfile.close(); } catch (Exception ex) { } --- Yours sincerely, Ivan Latysh. [EMAIL PROTECTED] http://ivan.yourmail.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: FOP exception
While Ivan's reply is correct, it is really a bit quick and dirty. For less experienced Java programmers a slightly fuller explanations is: Any method in Java can choose to throw an exception if something goes wrong. The caller of that function must be prepared to handle any exceptions that may be thrown and then do whatever they think is most appropriate. What Ivan's sample code does is catch any exception ( remember all exceptions extend the class java.lang.Exception) and ignore the error. 'Swallowing' exceptions in his way is generally a bad practice as when something goes wrong, you never find out about it. The minimum you should do is either: rethrow the exception to your caller or print a stack trace. Very often you will want to handle different types of exceptions in a special way and so should catch org.apache.fop.apps.FOPException for example. Trev IvanLatysh ivan@yourmail To: [EMAIL PROTECTED] .comcc: Subject: Re: FOP exception 11/12/2001 08:32 AM Please respond to fop-dev Hello, SHU! You wrote to [EMAIL PROTECTED] on Mon, 10 Dec 2001 12:21 -0800: Put all this code in try block. Like this try{ File xmlf = new File(c:/jdk1.3.1/xslfoRef.xml); File xslf = new File(c:/jdk1.3.1/xml2pdf.xsl); File writefile = new File(shu.pdf); Driver driver = new Driver(); driver.setRenderer(Driver.RENDER_PDF); InputHandler inputHandler = new XSLTInputHandler(xmlf, xslf); XMLReader parser = inputHandler.getParser(); InputSource inputSource = inputHandler.getInputSource(); driver.setOutputStream(new FileOutputStream(shu.pdf)); driver.render(parser, inputSource); //outfile.close(); } catch (Exception ex) { } --- Yours sincerely, Ivan Latysh. [EMAIL PROTECTED] http://ivan.yourmail.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]