Handling multiple exceptions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
In my application, i want to execute same piece of code for multiple exceptions caught. Is there any way to do this apart from writing the piece of code in a function and calling taht functions from all these exceptions
eg
tr

func1()

catch(exp1
{
catch(exp2
{

I want to execute same piece of code for exp1 and exp2 and i don't want to write that code in a separate function.
 
Mili said:
In my application, i want to execute same piece of code for multiple
exceptions caught. Is there any way to do this apart from writing the
piece of code in a function and calling taht functions from all these
exceptions.
eg.
try
{
func1();
}
catch(exp1)
{}
catch(exp2)
{}

I want to execute same piece of code for exp1 and exp2 and i don't
want to write that code in a separate function.

Well, one alternative is:

catch (Exception e)
{
if (e is exp1 || e is exp2)
{
}
else
{
throw;
}
}
 
Back
Top