in application, want send logs in case of crash remote server. have added try-catch block , in catch i'm sending logs server. want know exceptions should catch. need logs in case of every crash can fix it. practice catch exceptions?
thanks in advance.
here summarized list of suggestions curated other great answers:
catch unhandled exceptions.
create
exceptionhandlerimplementsjava.lang.thread.uncaughtexceptionhandler. can use class customize , log errors.put this:
thread.setdefaultuncaughtexceptionhandler(new uncaughtexceptionhandler(this));insideoncreate()method (aftersuper()) of each ofactivityclass .for details, please refer great answer android exception handling best practice .
enclose try/catch around codes run externally/from outside. (e.g - codes using 3rd party components)
enclose try/catch around codes know, can fail on conditions
- when there no internet connections
- during i/o operations
- when there potential crazy user inputs
- when there potential divide 0 situations
use try/catch @ top level because exceptions bubbled top level. so, in inner functions, if need be, can consider using
throwexception. then, @ top level, catch specific exceptions , sort exception types in catch block correctly. (referred great answer: how using try catch exception handling best practicefor ui, should offer "continued usability" providing "limited functionality" version of app if error occurs (if error due to, example, no internet connectivity).
over-eager error reporting user not idea.
persistent error messages bad. inform user message , let user close/remove it.
reference 1 | reference 2 | reference 3 | further reading 1 | further reading 2 | further reading 3
for android library remotely log unhandled exceptions, can take @ this: android-remote-stacktrace .
- download .jar file.
- add java build path.
add internet permission: uses-permission android:name="android.permission.internet"
in
oncreatemethod of activity or service, put 'exceptionhandler.register(this, "http://your.domain/path");'- on server, place this php file, can edit extend functionality.
Comments
Post a Comment