Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to catch Fatal Exception thrown from a referenced library?

I am using a referenced library called 'rome-1.0.jar'.

try {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(file));
}
catch(Exception e) {
    Log.e("", "ROME parse error: " + e.toString());
}

input.build(new XmlReader(file)); is 'rome-1.0.jar' library call.

Although I am catching all Exceptions, my app still crashes.

05-31 13:43:06.297: W/dalvikvm(11150): threadid=22: thread exiting with uncaught exception (group=0x40a4d1f8)
05-31 13:43:06.307: E/AndroidRuntime(11150): FATAL EXCEPTION: Thread-4199
05-31 13:43:06.307: E/AndroidRuntime(11150): java.lang.NoClassDefFoundError: java.beans.PropertyDescriptor[]
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.impl.BeanIntrospector.getPropertyDescriptors(BeanIntrospector.java:39)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.impl.CloneableBean.beanClone(CloneableBean.java:129)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.impl.ObjectBean.clone(ObjectBean.java:87)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.module.DCModuleImpl.clone(DCModuleImpl.java:771)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.module.impl.ModuleUtils.cloneModules(ModuleUtils.java:35)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.synd.impl.ConverterForRSS090.createSyndEntry(ConverterForRSS090.java:90)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.synd.impl.ConverterForRSS091Userland.createSyndEntry(ConverterForRSS091Userland.java:85)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.synd.impl.ConverterForRSS092.createSyndEntry(ConverterForRSS092.java:46)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.synd.impl.ConverterForRSS093.createSyndEntry(ConverterForRSS093.java:37)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.synd.impl.ConverterForRSS094.createSyndEntry(ConverterForRSS094.java:58)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.synd.impl.ConverterForRSS090.createSyndEntries(ConverterForRSS090.java:79)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.synd.impl.ConverterForRSS090.copyInto(ConverterForRSS090.java:64)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.synd.impl.ConverterForRSS091Userland.copyInto(ConverterForRSS091Userland.java:49)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.synd.impl.ConverterForRSS094.copyInto(ConverterForRSS094.java:47)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.feed.synd.SyndFeedImpl.<init>(SyndFeedImpl.java:144)
05-31 13:43:06.307: E/AndroidRuntime(11150):    at com.sun.syndication.io.SyndFeedInput.build(SyndFeedInput.java:123)
...(my code)

Is there a way to handle this?

like image 466
jclova Avatar asked May 31 '12 17:05

jclova


2 Answers

Thank you Kumar, you gave me an idea.

I didn't know this was an error. I have handled OutOfMemoryError before so I know I am able to handle errors.

try {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(file));
}
catch(Exception e) {
    Log.e("", "ROME parse error: " + e.toString());
}
catch(Error e2) {
    Log.e("", "ROME parse error2: " + e2.toString());
}

Above code handles errors. I know it's not a good idea to do so, but it serves my purpose.

Thank you.

like image 125
jclova Avatar answered Nov 01 '22 09:11

jclova


This is not an exception, rather an error, whose nature is more severe than exceptions. You are not supposed to handle errors.

http://www.coderanch.com/t/269746/java-programmer-SCJP/certification/Error-vs-Exception

If errors happen, the system will, in most of the cases become unstable, and you really can't do anything about it.

like image 34
Kumar Bibek Avatar answered Nov 01 '22 11:11

Kumar Bibek