Given the following code:
try
// code1
try
// code2
catch ex as exception
end try
// code3
catch ex as exception
end try
Are there any side effects to naming the two exception variables the same or should they have different names?
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.
Nope, that should be fine. They’re entirely independent variables. At least, that’s the case in C# – I couldn’t say for certain in VB, but I’d be really surprised if there were any side-effects beyond potential confusion when reading the code 🙂
In particular, the two variables have different scopes, as neither is really nested within the block declaring the other – the “inner” one is declared within the outer try block. If you wrote a try/catch block within the catch block then that nested catch block couldn’t reuse the same variable name.