0

I am provoking a CSS file load error for internal porpuses, to see if it handles a problem like this.

The code that I have is this, and when it arrives at renderer.setDocument(), a method from ITextRenderer class, it throws an uncaughtable exeception, that we need to catch, and even in this case it continues to renderer.layout() and then to finally{} block.

private ITextRenderer renderPdfByRenderer(
                final ITextRenderer renderer,
    ...
                  {
    ...

            try {
    ...
                org.w3c.dom.Document xhtmlContent = createDocument(contentReader);

    ...

                renderer.setDocument(xhtmlContent, FacesContextHelper.getRequest().getRequestURL().toString());

    ...      

                renderer.layout();

    ....

            } catch (final SAXException e) {
                throw getExceptionOnRender(e);
            } catch (final ParserConfigurationException e) {
                throw getExceptionOnRender(e);
            } catch (final DocumentException e) {
                throw getExceptionOnRender(e);
            } catch (IOException e) {
                e.printStackTrace();
                throw getExceptionOnRender(e);
            } catch (final ServletException e) {
                throw getExceptionOnRender(e);
            }
            finally{
               ...
            }
        }

[err] java.io.IOException: Stream closed [err] at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134) [err] at java.io.BufferedInputStream.read1(BufferedInputStream.java:256) [err] at java.io.BufferedInputStream.read(BufferedInputStream.java:317) [err] at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264) [err] at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) [err] at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) [err] at java.io.InputStreamReader.read(InputStreamReader.java:167) [err] at org.xhtmlrenderer.css.parser.Lexer.zzRefill(Lexer.java:1634) [err] at org.xhtmlrenderer.css.parser.Lexer.yylex(Lexer.java:1865) [err] at org.xhtmlrenderer.css.parser.CSSParser.next(CSSParser.java:1807) [err] at org.xhtmlrenderer.css.parser.CSSParser.la(CSSParser.java:1819) [err] at org.xhtmlrenderer.css.parser.CSSParser.stylesheet(CSSParser.java:159) [err] at org.xhtmlrenderer.css.parser.CSSParser.parseStylesheet(CSSParser.java:89) [err] at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:78) [err] at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:95) [err] at org.xhtmlrenderer.context.StylesheetFactoryImpl.getStylesheet(StylesheetFactoryImpl.java:174) [err] at org.xhtmlrenderer.context.StyleReference.readAndParseAll(StyleReference.java:123) [err] at org.xhtmlrenderer.context.StyleReference.setDocumentContext(StyleReference.java:111) [err] at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:182) [err] at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:145) [err] at osplus.mcp.frontend.servlet.RendererFilter.renderPdfByRenderer(RendererFilter.java:750) [err] at osplus.mcp.frontend.servlet.RendererFilter.renderPdf(RendererFilter.java:697) [err] at osplus.mcp.frontend.servlet.RendererFilter.handleReport(RendererFilter.java:1265) [err] at osplus.mcp.frontend.servlet.RendererFilter.doFilter(RendererFilter.java:178) [err] at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:194) [err] at [internal classes]

Can anyone please help me to understand how can I catch this exception?

Thank you.

Regards

1 Answers1

1

You can catch a specific exception like this:

try {
   (ITextRenderer(a))setDocument(..)..
} catch (IOException ioe){
    ioe.printStackTrace();
}

However, if you can not catch the exception, it may be because the API does not allow you to, and instead it just dumps the stack and tries to handle the exception itself. Double check the parameters that are passed in to ensure you cannot filter out the error conditions yourself. If you are using an advanced IDE (eg. Eclipse), you should be able to set a breakpoint when the IOException is thrown so you can analyze what is going on. Also you can try and follow the source code to see it it tells you anything. Furthermore if you cannot resolve it, try contact the authors of the code.

ergonaut
  • 6,929
  • 1
  • 17
  • 47
  • Hi @ergonaut, thank you for your help. The thing is that our code is inside a try catch code block, but even with that, and with your catch, the code does not go to the catch block, and I do not know why. In my post below I will put a little bit of the code that we are producing. – Luís Daniel Simões Nov 09 '15 at 10:06