android - Send an Exception variable to a function and return the exception details -


i working on android library need pass exception object function. function should cope exception types , able return of available data within exception, such error message, stacktrace , inner exception.

below how passing exception variable function within catch statement.

try {     txttext = (edittext)findviewbyid(r.id.txttestedit);     string test = txttext.gettext().tostring(); } catch (nullpointerexception ex) {     crashreporter.reportcrash(ex); } 

below function needs extract exception type.

public static void reportcrash(object exceptionobject) {     string exceptiontype = exceptionobject.getclass().getname();     log.d("exception type", exceptiontype);      } 

in example exception type java.lang.nullpointerexception. there way can return object called exceptionobject original exception extract stacktrace inner exception , error message.

please note, function should cope exception types not nullpointerexception

thanks can provide

the best way want use callback, each method can handle properly, but, if there no callback have default behavior.

this way can use properties in method had error.

this question goes more callbacks in android:

how define callbacks in android?

but, create interface implemented in similar fashion this:

crashreporter.reportcrash(ex, new exceptioncallback() {     public void myexceptioncallback(exception e) {     }   }); 

this code won't compile, show possible way implement it.

if class has 1 callback needed, can create callback listener earlier, , pass reportcrash method.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -