You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Chris Bamford <cb...@mimecast.com> on 2015/01/21 15:24:06 UTC

Runtime exception in PDFParser.parse()

Hi

Recently I started getting runtime exceptions in PDFParser.parse(), but I can't seem to get any information out as to why.  The weird thing is that it only happens on Linux - on my laptop it is fine!
I have tried to get a stack trace (my code uses log4j), but all I get is:


org.slf4j.impl.Log4jLoggerAdapter.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V

This is produced by my code:


try {
    log.info("Parsing PDF document ...");
    document = PDDocument.load(is, true);         // skip corrupt pdf objects

} catch (Throwable t) {
    message = "Failure when parsing PDF <" + filename + ">: " + t.getMessage();
    if (t1.getCause() != null) {
        message += " | CAUSE: " + t1.getCause().getMessage();
    }

    log.warn(t);
    log.debug(message);
    throw new Exception(message);
}

I have also tried to turn logging up in my log4j.properties:


log4j.logger.org.apache.pdfbox=TRACE

But I see nothing except the slf4j line above.

Can anyone tell me what I am doing wrong?

Thanks

- Chris
           
Chris Bamford
m: +44 7860 405292
www.mimecast.com
 
Mimecast
CityPoint
One Ropemaker Street, London, EC2Y 9AW
+44 (0) 207 847 8700
             

         
        
Disclaimer

cbamford@mimecast.com sent at 2015-01-21 14:24:10 is confidential and may be legally privileged. It is intended solely for use by users@pdfbox.apache.org and others authorized to receive it. If you are not users@pdfbox.apache.org
you are hereby notified that any disclosure, copying, distribution or taking action in reliance of the contents of this information is strictly prohibited and may be unlawful.

Mimecast Ltd. is a company registered in England and Wales with the company number 4698693 VAT No. GB 123 4197 34
Registered Office: CityPoint, One Ropemaker Street, Moorgate, London, EC2Y 9AW

This email message has been scanned for viruses by Mimecast. Mimecast delivers a complete managed email solution from a single web based platform. For more information please visit www.mimecast.com

mcst2013



Re: Runtime exception in PDFParser.parse()

Posted by John Hewson <jo...@jahewson.com>.
You don’t have to do anything to log runtime exceptions in Java, they are passed
up the stack until the process terminates and prints a stack trace. Trying to catch
runtime exceptions yourself isn’t necessary or advised.

Remove your exception handling code and have main() throw IOException.

-- John

> On 21 Jan 2015, at 06:24, Chris Bamford <cb...@mimecast.com> wrote:
> 
> 
> Hi
> 
> Recently I started getting runtime exceptions in PDFParser.parse(), but I can't seem to get any information out as to why.  The weird thing is that it only happens on Linux - on my laptop it is fine!
> I have tried to get a stack trace (my code uses log4j), but all I get is:
> 
> org.slf4j.impl.Log4jLoggerAdapter.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
> 
> This is produced by my code:
> 
> try {
>     log.info("Parsing PDF document ...");
>     document = PDDocument.load(is, true);         // skip corrupt pdf objects
> 
> } catch (Throwable t) {
>     message = "Failure when parsing PDF <" + filename + ">: " + t.getMessage();
>     if (t1.getCause() != null) {
>         message += " | CAUSE: " + t1.getCause().getMessage();
>     }
> 
>     log.warn(t);
>     log.debug(message);
>     throw new Exception(message);
> }
> I have also tried to turn logging up in my log4j.properties:
> 
> log4j.logger.org.apache.pdfbox=TRACE
> 
> But I see nothing except the slf4j line above.
> 
> Can anyone tell me what I am doing wrong?
> 
> Thanks
> 
> - Chris
> 
> 
>  <https://serviceb.mimecast.com/mimecast/click?account=C1A1&code=656191af743569eae379793cda49427f>
> Chris Bamford	m: +44 7860 405292	w: www.mimecast.com <http://www.mimecast.com/>
> Senior Developer	p: +44 207 847 8700	Address click here <http://www.mimecast.com/About-us/Contact-us/>
>  <https://serviceb.mimecast.com/mimecast/click?account=C1A1&code=c01462327e2d761c3b717eed2058e1ac>	
>  	
>  <https://serviceb.mimecast.com/mimecast/click?account=C1A1&code=6540a5ba8d3a7ff2665c11f28f8051e6>	
>  <https://serviceb.mimecast.com/mimecast/click?account=C1A1&code=09b8c0f1a6d966cb67b03d293176fc22>	
>  <https://serviceb.mimecast.com/mimecast/click?account=C1A1&code=f1e6756b7727ee7b1d3b5c55d10a456d>	
>  <https://serviceb.mimecast.com/mimecast/click?account=C1A1&code=4d6b5c1310552b6f6f8dc52c397041ba>	
>  <https://serviceb.mimecast.com/mimecast/click?account=C1A1&code=7fb112818d2f83f403ac7d7380fc47c9>
> Disclaimer
> The information contained in this communication from cbamford@mimecast.com sent at 2015-01-21 14:24:10 is confidential and may be legally privileged. It is intended solely for use by users@pdfbox.apache.org and others authorized to receive it. If you are not users@pdfbox.apache.org you are hereby notified that any disclosure, copying, distribution or taking action in reliance of the contents of this information is strictly prohibited and may be unlawful.
> 
> Mimecast Ltd. is a company registered in England and Wales with the company number 4698693 VAT No. GB 123 4197 34 Registered Office: CityPoint, One Ropemaker Street, Moorgate, London, EC2Y 9AW
> 
> This email message has been scanned for viruses by Mimecast. Mimecast delivers a complete managed email solution from a single web based platform. For more information please visit http://www.mimecast.com <http://www.mimecast.com/>