When is an attempt not to catch an attempt to catch?

I have a funny problem when try / catch blocks are apparently ignored on the stack when the application stops.

I do not have a working test project (but because of the deadline, otherwise I would completely try to reproduce it), but consider the following code fragment.

class IndexNotFoundException : Exception { }

public static string RunAndPossiblyThrow(int index, bool doThrow)
{
    try
    {
        return Run(index);
    }
    catch(IndexNotFoundException e)
    {
         if(doThrow)
             throw;
    }
    return "";
}

public static string Run(int index)
{
    if(_store.Contains(index))
        return _store[index];
    throw new IndexNotFoundException ();
}

public static string RunAndIgnoreThrow(int index)
{
    try
    {
        return Run(index);
    }
    catch(IndexNotFoundException e)
    {
    }
    return "";
}

During operation, this template works cool. We get outdated code support that relies on exceptions to control the program (bad), and we get the opportunity to move forward and slowly remove the exceptions used to control the program.

, "Run", "doThrow" "RunAndPossiblyThrow". , , , "RunAndIgnoreThrow", .

. , , , .

, ,

, , , , . , , , . , , , " " 400 + mb Windbg. Win7 64 . , .

- .

class IndexNotFoundException : Exception { }

public static string RunAndPossiblyThrow(int index, bool doThrow)
{
    try
    {
        return Run(index);
    }
    catch
    {
    }
    return "";
}

public static string Run(int index)
{
    if(_store.Contains(index))
        return _store[index];
    throw new IndexNotFoundException ();
}

, , , , -

class IndexNotFoundException : Exception { }

public static string RunAndPossiblyThrow(int index, bool doThrow)
{
    try
    {
        return Run(index);
    }
    catch
    {
    }
    return "";
}

public static string Run(int index)
{
    if(_store.Contains(index))
        return _store[index];
    return "";
}

, , .

... ...

class IndexNotFoundException : Exception { }

public static string RunAndPossiblyThrow(int index, bool doThrow)
{
    try
    {
        throw new IndexNotFoundException();
    }
    catch
    {
    }
    return "";
}

, . , , catch . . , , , catch .

EDIT -, . , , 10 . .dmp , , .

, , , , ...

+5
5

. , - , ApplicationException, .

+4

"finally"? , try/catch? , try/catch , .

, - .

0

, Run. , _store null -.

0

, :

  • AppDomain.CurrentDomain.UnhandledException, , - , .

  • Application.ThreadException, , .

  • , - , ?

0

All Articles