Why is .NET exception not caught by try/catch block?

前端 未结 25 743
Happy的楠姐
Happy的楠姐 2020-12-04 19:24

I\'m working on a project using the ANTLR parser library for C#. I\'ve built a grammar to parse some text and it works well. However, when the parser comes across an illeg

25条回答
  •  萌比男神i
    2020-12-04 20:05

    Personally I'm not convinced by the threading theory at all.

    The one time I've seen this before, I was working with a library which also defined Exception and the usings I had meant that the actual Catch was referring to a different "Exception" type (if it had been fully qualified it was Company.Lib.Exception but it wasnt because of the using) so when it came to catching a normal exception that was being thrown (some kind of argument exception if I remember correctly) it just wouldn't catch it because the type didn't match.

    So in summary, is there another Exception type in a different namespace that is in a using in that class?

    EDIT: A quick way to check this is make sure in your catch clause you fully qualify the Exception type as "System.Exception" and give it a whirl!

    EDIT2: OK I've tried the code and concede defeat for now. I'll have to have another look at it in the morning if no one has come up with a solution.

提交回复
热议问题