gpt4 book ai didi

java - 如何捕获除特定异常之外的所有异常?

转载 作者:IT老高 更新时间:2023-10-28 20:45:06 25 4
gpt4 key购买 nike

是否可以捕获方法的所有异常,除了应该抛出的特定异常?

void myRoutine() throws SpecificException { 
try {
methodThrowingDifferentExceptions();
} catch (SpecificException) {
//can I throw this to the next level without eating it up in the last catch block?
} catch (Exception e) {
//default routine for all other exceptions
}
}

/旁注:标记的“重复”与我的问题无关!

最佳答案

void myRoutine() throws SpecificException { 
try {
methodThrowingDifferentExceptions();
} catch (SpecificException se) {
throw se;
} catch (Exception e) {
//default routine for all other exceptions
}
}

关于java - 如何捕获除特定异常之外的所有异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20355824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com