导航

自定义捕获异常

Posted on 2017-02-16 14:10  _eve  阅读(194)  评论(0编辑  收藏  举报

package com.yunfengtech;

import java.text.ParseException;

public class Throw {
/**
* 处理激活
* @throws ParseException
*/
public void test(int aaa)throws ServiceException{
int bbb = aaa;
if(bbb >= 1) {
if(bbb >= 2) {
if(bbb >= 3) {
if(bbb >= 4) {
throw new ServiceException("0");
} else {
throw new ServiceException("4");
}
} else {
throw new ServiceException("3");
}
} else {
throw new ServiceException("2");
}
} else {
throw new ServiceException("1");
}
}


/*public static void main(String args[]) throws ServiceException {
Throw a = new Throw();
a.test(4);
}
Exception in thread "main" com.yunfengtech.ServiceException: 0
at com.yunfengtech.Throw.test(Throw.java:16)
at com.yunfengtech.Throw.main(Throw.java:34)*/
/*public static void main(String args[]) {
Throw a = new Throw();
try {
a.test(4);
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
com.yunfengtech.ServiceException: 0
at com.yunfengtech.Throw.test(Throw.java:16)
at com.yunfengtech.Throw.main(Throw.java:35)*/

}