集册 Java实例教程 捕获所有错误和异常

捕获所有错误和异常

欢马劈雪     最近更新时间:2020-01-02 10:19:05

594
捕获所有错误和异常

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(
展开阅读全文