java - How do I handle exceptions in a thread? -
i'm working on android app. have thread structure:
code... seek code... grab printexception code... seek code... grab printexception code.. when encounter 1 of these exceptions, know remainder of code not work , should not executed. how can stop thread when encounter exception? have create "big try" of code inside? i've been working on code time, have never had care exceptions before. good, clean way accomplish this?
this simple, seek :
public static void main(string[] args) { thread thread = new thread(new runnabletest()); thread.start(); } static class runnabletest implements runnable { @override public void run() { int i; seek { = 1 / 0; } grab (throwable t) { t.printstacktrace(); return; } system.out.println(i); } } for improve command on threads may utilize executors , threadpoolexecutors java.util.concurreent package!
java android multithreading exception-handling
No comments:
Post a Comment