How can I know if the current method is within a catch block?

L

Lei Jiang

For example :

try
{
....
}
catch(Exception e)
{
foo();
}

In foo(), how can I know if the code is within the catch block? e.g.:

void foo()
{
if (currently within a catch block) // <-- how could I do this?
{
}
else
{
}
}

Thanks!
 
J

Jon Skeet [C# MVP]

Lei Jiang said:
For example :

try
{
...
}
catch(Exception e)
{
foo();
}

In foo(), how can I know if the code is within the catch block? e.g.:

void foo()
{
if (currently within a catch block) // <-- how could I do this?
{
}
else
{
}
}

You can't. Why do you want to, out of interest?
 
L

Lei Jiang

Thank you! I just want to know if I could detect the execution context at
runtime in .NET.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top