I am not sure what the best way to handle RuntimeExceptionin a thread. Let's say I have thread A, which uses a third-party function b()to send data to server S. Now it b()can throw some RuntimeException and not send data to the specified server. In this case, I need to run a method c()that transfers data to the local database. Now the method c()can also throw RuntimeExceptionif it cannot write to db.
Example:
public class A() extends Runnable {
@Override
public void run() {
b(data, "<some https end point>");
}
}
Now, if it b()does not work as expected, I need to execute the method c().
One way to handle this is to wrap b()and c()around the try-catch block and catch a RuntimeException as follows
public void run() {
try {
b(data, "<some https end point>");
} catch (RuntimeException e) {
try {
c(data)
} catch(RuntimeException e) {
}
}
}
, . , , Future ( - ). ? , ?