Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch all exceptions and send them by e-mail

In my app I want to catch all types of exceptions and send reports by e-mail. For that I'm using global try catch block. But now I need to recognize exception by type. How can I do it?

try{
...
}
catch (Exception e){
//Here I need to recognize exception by type
send(Error);
}
like image 440
XXX Avatar asked Dec 21 '22 02:12

XXX


2 Answers

Why you don't simple send the whole stacktrace?

send(e.getStackTrace())

It not only contains the Exception type but also where (file, class, line) it occurred. Additionally, you can also simply use the toString() method.

See the java doc for further information

like image 134
poitroae Avatar answered Jan 01 '23 14:01

poitroae


Instead of rolling your own error logging and reporting mechninism I strongly recommend you use ACRA Its free, open source, and supports sending error logs to email. I have used it for quite some time and it is very good.

This will give you all sorts of information such as phone make, model, resolution, free memory, as well as a full stack trace of the error. Its by far the easiest way to get quality error reporting into an Android app.

The best part is it takes all of about 5 minutes to get setup and integrated.

like image 33
w.donahue Avatar answered Jan 01 '23 13:01

w.donahue