Is possible to catch more then one exception in the same catch block?
try
{ }
catch(XamlException s | ArgumentException a)
{ }
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes. If you catch a superclass, it will also catch all subclasses too:
If this catches more than you wanted then you can rethrow the exceptions that you didn’t intend to catch by testing their type. If you do this, be careful to use the
throw;syntax, and notthrow e;. The latter syntax clobbers the stacktrace information.But you can’t catch two different types using the syntax you propose.