Java exception thrown

How can it be? It seems that as daylight, an exception from a third-party library skips my catch block. Not sure where to start troubleshooting. Either I was really stupid or I didn’t understand anything subtle about exceptions and Java.

My console:

Exception: org.apache.james.mime4j.io.MaxLineLimitException: Maximum line length limit exceeded; stack: org.apache.james.mime4j.stream.MimeEntity.readRawField(MimeEntity.java:242); org.apache.james.mime4j.stream.MimeEntity.nextField(MimeEntity.java:258); org.apache.james.mime4j.stream.MimeEntity.advance(MimeEntity.java:296); org.apache.james.mime4j.stream.MimeTokenStream.next(MimeTokenStream.java:360); me.unroll.scanner.Scanner.<init>(Scanner.java:206); me.unroll.scanner.ScannerThread.run(ScannerThread.java:205); java.lang.Thread.run(Thread.java:722)

The problem is that my code is as follows:

try {  
//...
 for(EntityState token = messageStream.getState();
    token != EntityState.T_END_OF_STREAM;
    token = messageStream.next()) {  //this is Scanner.java:206
//...
catch(ScanComplete exc) { }
catch(MaxLineLimitException exc) { //line 282, matches "try" above
    debug("Am I getting caught?"); //no, it not

I more

+5
source share
3 answers

You are trying to catch the wrong type of exception.

The signature for MimeTokenStream.next()says she can quit MimeException, which you do not catch. (By the way, if you are wondering why the exception is not caught, you can try to catch Exceptionand register the type of exception to see what actually throws.)

, , 242 MimeEntity.readRawField, :

241        } catch (MaxLineLimitException e) {
242            throw new MimeException(e);
243        }

, MaxLineLimitException, , , MimeException. MimeException MaxLineLimitException, , MimeTokenStream.next() , , MimeException , , .

+5

, , . , .

+1

" ", , . , MaxLineLimitException.

+1

All Articles