62,615
社区成员
发帖
与我相关
我的任务
分享
try{
/*调用jar包中的方法,由于网络原因一定会抛出异常.一开始我以为是抛出的异常有问题,然后改成 throw new Exception("")
结果还是捕获不到,导致代码无法进入到catch块,就自动结束了*/
}catch(Exception e){
/*这里一直无法catch到上面方法抛出的异常:由于要针对异常进行业务处理,必须要捕获异常*/
throw e;
}
public Boolean autoPrintTask(String sOrderId, long nVmTaskId,
long nWorkflowId, String sTaskType, String sRegionId)
throws Exception{
Boolean rtnIsWait = new Boolean(true);
try {
CenterFactory.pushCenterInfo(
CenterConst.ICenter.ICenterType.RegionId, sRegionId);
IBOSfOrderValue iOrder = ServicefulfilFactory.getISfOrderSV()
.getIBoSfOrderValue(Long.parseLong(sOrderId));
IBOSfTaskInsValue iTask = ServicefulfilFactory.getISfTaskInsSV().getSfTaskInsValue(nVmTaskId);
rtnIsWait = ServicefulfilFactory.getISfTaskInsSV().autoPrintTask(iTask, iOrder);
//自动打单执行外部任务成功,引擎任务直接结束,sf工单需相应处理
if(!rtnIsWait.booleanValue()){
ServicefulfilFactory.getISfTaskInsSV().finishAutoTask(iTask, iOrder);
}
} catch (Exception t) {
throw new Exception("comframe自动打单回调失败:" + t.getMessage());
}
return rtnIsWait;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread t, Throwable e) {
System.out.println("catched it :" + t.getName() + "," + e);
}
}
class ExceptionThread implements Runnable {
public void run() {
Thread t = Thread.currentThread();
System.out.println("run() by " + t);
System.out.println("eh=" + t.getUncaughtExceptionHandler());
throw new RuntimeException();
}
}
public class SettingDefaultHandler {
public static void main(String[] args) {
Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
ExecutorService exec = Executors.newCachedThreadPool();
exec.execute(new ExceptionThread());
}
}
[/quote]解决了,异常能被捕捉了.谢谢了,又是个知识点
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread t, Throwable e) {
System.out.println("catched it :" + t.getName() + "," + e);
}
}
class ExceptionThread implements Runnable {
public void run() {
Thread t = Thread.currentThread();
System.out.println("run() by " + t);
System.out.println("eh=" + t.getUncaughtExceptionHandler());
throw new RuntimeException();
}
}
public class SettingDefaultHandler {
public static void main(String[] args) {
Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
ExecutorService exec = Executors.newCachedThreadPool();
exec.execute(new ExceptionThread());
}
}