MyException 自定义异常

public class MyException extends Exception{
 
 public MyException(){
  super();
 }
 public MyException(String msg){
  super(msg);
 }
}

 

 

public class Test extends TestCase{
 private static Logger logger = LoggerFactory.getLogger(Test.class);

 

 

public void test9() throws MyException{
  try{
   int a = Integer.valueOf("a");
  }catch(Exception e){
   throw new MyException("zzzzzzzzz");
  }
 }

 


 public void test10(){
  Test test = new Test();
  try{
   test.test9();
  }catch(MyException e){
   logger.info("程序出错");
   logger.error("chengxuchucuo");
   System.out.println(e.getMessage());
  }
 }

}

 

输出:14:57:19.194 [main] INFO  com.test.Test - 程序出错
14:57:19.226 [main] ERROR com.test.Test - chengxuchucuo
zzzzzzzzz

你可能感兴趣的:(java)