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
What happens if an exception is not caught? If an exception is not caught (with a catch block), the runtime system will abort the program (i.e. crash) and an exception message will print to the console.
Exceptions that Can't be Caught One such exception is the limit exception ( System. LimitException ) that the runtime throws if a governor limit has been exceeded, such as when the maximum number of SOQL queries issued has been exceeded.
The only exception that cannot be caught directly is (a framework thrown) StackOverflowException. This makes sense, logically, as you don't have the space in the stack to handle the exception at that point.
Yes, It is possible to have a try block without a catch block by using a final block. As we know, a final block will always execute even there is an exception occurred in a try block, except System.
One possibility is that the exception was logged, subsequently caught and not rethrown. You can put a breakpoint on the exception itself and step out from there until you reach your method.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With