How to use Java-style throws keyword in C#?

前端 未结 10 2193
说谎
说谎 2020-11-27 04:39

In Java, the throws keyword allows for a method to declare that it will not handle an exception on its own, but rather throw it to the calling method.

Is there a sim

10条回答
  •  广开言路
    2020-11-27 05:15

    For those wondering, you do not even need to define what you catch to pass it on to the next method. In case you want all your error handling in one main thread you can just catch everything and pass it on like so:

    try {
        //your code here
    }
    catch {
        //this will throw any exceptions caught by this try/catch
        throw;
    }
    

提交回复
热议问题