Reputation: 1341
I'm trying to integrate Facebook into my app so I followed all the instructions. When running it, after onResume event finishes, I get an exception that I can't catch from my code.
Is there a way to set a general exception catcher so no matter what, it will catch it?
The emulator does not throw any exception at all so I can't use it for this
Update: I found it here: Using Global Exception Handling on android
The error came from Facebook itself and it is related to working with proguard
Upvotes: 0
Views: 1337
Reputation: 2124
The Throwable class is the superclass of all errors and exceptions in the Java language.
If you catch a throwable you can catch all kind of errors and exceptions.
try {
// code
} catch(Throwable e) {
// handle throwable
}
However this is strongly not recommended and bad practise/design. You should never catch generic errors and exceptions. You should analyse your specific exception and solve the problem instead of simply ignoring it with try/catch!
Upvotes: 1
Reputation: 580
try this solution:
implement Thread.UncaughtExceptionHandler
(this
class going to handle with the uncaughtExceptions), lets call this
class ExceptionHandler. extends Application
,
lets call this class App, and don't forget to declare this in the
manifest file under application tag: android:name="your_package_path.App"
onCreate()
, and add this line: Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
Upvotes: 1
Reputation: 164
There is a base Exception class. So if you do like this:
try {
...anything...
}catch(Exception e) {
e.printStackTrace();
}
you'll catch any exception that is thrown by any method called from within the try block. But remember that exceptions aren't always thrown. Sometimes there's just no result to return, or something.
Upvotes: 0