开发者

Exceptions not being caught

开发者 https://www.devze.com 2022-12-22 01:11 出处:网络
We have following code: try { // some code throwing MyException } catch (MyException ex) { // [1] // no (re)throw here

We have following code:

try 
{
    // some code throwing MyException
}
catch (MyException ex)
{
    // [1]
    // no (re)throw here
}
catch (E开发者_运维技巧xception ex)
{
    if (ex is MyException)
    {
        // [2]
    }
}

If we run the code without a debugger attached, everything runs fine. However, if we debug the code, we don't get to point [1] but [2]. As far as I understand the language specification this should not be possible.

Even weirder, this code used to run fine even while debugging. The strange behavior started only a few days ago.


Depending on original sources, it may be related to this issue : Why can't I catch a generic exception in C#?


Check that you have done a full rebuild and are using the correct pdb files. Also check that you don't have some conditionally compiled code changing things (i.e. code between #if DEBUG statements).

0

精彩评论

暂无评论...
验证码 换一张
取 消