捕获所有错误和异常
import java.util.logging.Level; import java.util.logging.Logger; /* 来 自 N o w J a v a . c o m*/ class BgThread extends Thread { Logger logger = Logger.getLogger("com.mycompany.mypackage"); BgThread() { setDaemon(true); } // Set to true to shut down this thread boolean stop = false; public void run() { while (!stop) { try { // Perform work here } catch (Throwable t) { // Log the exception and continue logger.log(