Catch the exception that happens to be a parent class in the exception hierarchy Do_stuff() except exception as err Both constructs (catch () being a syntax error, as sh4nx0r rightfully pointed out) behave the same in c#
The NFL’s best catches ever: Justin Jefferson, David Tyree, Julian Edelman - Sports Illustrated
The fact that both are allowed is probably something the language inherited from c++ syntax
Others languages, including c++/cli, can throw objects that do not derive from system.exception
David, that only applies to the catch (exception e) part And that is separate from throw vs throw e. Try/catch should enclose exactly what you want to capture an exception for If you're looking explicitly for errors coming from this.user.create() then you wouldn't put anything else inside the try/catch.
Is there a way to catch both exceptions and only set webid = guid.empty once The given example is rather simple, as it's only a guid, but imagine code where you modify an object multiple times, and if one of the manipulations fails as expected, you want to reset the object. In the second scheme, if the promise p rejects, then the.catch() handler is called If you return a normal value or a promise that eventually resolves from the.catch() handler (thus handling the error), then the promise chain switches to the resolved state and the.then() handler after the.catch() will be called
71 best practice is that exception handling should never hide issues
However, if you're expecting an exception it's usually better practice to test for it first. I want to catch and log exceptions without exiting, e.g., try