Java examples for Language Basics:try catch finally
Catching all Errors and Exceptions
import java.util.logging.Level; import java.util.logging.Logger; class BgThread extends Thread { Logger logger = Logger.getLogger("com.mycompany.mypackage"); BgThread() {//from w w w . j a v a2 s . c o m 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(Level.SEVERE, "Unexception exception", t); } } } }