Forcing nested try/catch to catch outer exception?

Hello all,

Assume we have a nested try/catch like following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
try
{
   try
   {
      ...
   }
   catch
   { 
      ...
   }
   ...
}
catch
{
   ...
}


If the inner exception gets thrown, is there any way to then force the outer one to get caught? I don't have much experience with exceptions, so correct me if I'm wrong, but normally the inner exception would get caught and then execution would continue as normal.

If there's no way to do this, then what's the standard way of knowing exactly where the exception came from (that's the only reason I have nested try/catch)

Thanks.
Last edited on
Do another throw:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
try
{
  try
  {
  }
  catch(...)
  {
    if( you_want_this_exception_to_be_caught_by_outer_block )
      throw;
  }
}
catch(...)
{
}


Using throw; without actually specifying something to throw simply rethrows the last exception.

EDIT:

If there's no way to do this, then what's the standard way of knowing exactly where the exception came from (that's the only reason I have nested try/catch)


Why not put that information inside the exception object?
Last edited on
Topic archived. No new replies allowed.