Java exception not being caught
exception, java
Solution
You're attempting to catch the wrong exception type.
The signature for `MimeTokenStream.next()` says it can throw `MimeException`, which you are not catching. (BTW if you are wondering why an exception isn't being caught, you can try catching `Exception` and logging the exception type to see what is actually being thrown.)
Now, if you look at the source code for the actual source of the exception, line 242 of `MimeEntity.readRawField`, you'll see:
241 } catch (MaxLineLimitException e) {
242 throw new MimeException(e);
243 }
So even though the console message says `MaxLineLimitException`, the actual exception being thrown by that method is a `MimeException`. Try catching `MimeException` in your code instead of `MaxLineLimitException`, but beware that `MimeTokenStream.next()` can probably throw `MimeException` for other reasons besides the one you've encountered.
Problem
How can this be? Looks like plain as daylight an exception from a third party library is skipping my catch block. Not sure where to begin troubleshooting this. It's either me being really stupid, or me not understanding something 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)` Problem is my code looks like this: ``` 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's not ``` I'm more