Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些这样的代码:
try { doStuff(); } catch(SpecificException) { if(e.Message == interestingMessage) doOtherStuff(); else throw; } catch(Exception e) { doSomethingElse(); }
当第一个 catch 块重新抛出它的异常时,它会被第二个 catch 块捕获吗?
不,如果您将异常重新抛出给方法调用者。
if inside SpecificExceptioncatch 表示您需要将该异常拆分为(至少)两种不同的类型。
SpecificException