Why catch and rethrow an exception in C#?

前端 未结 17 1026
遥遥无期
遥遥无期 2020-11-22 14:56

I\'m looking at the article C# - Data Transfer Object on serializable DTOs.

The article includes this piece of code:

public static string Se         


        
17条回答
  •  星月不相逢
    2020-11-22 15:13

    You don't want to throw ex - as this will lose the call stack. See Exception Handling (MSDN).

    And yes, the try...catch is doing nothing useful (apart from lose the call stack - so it's actually worse - unless for some reason you didn't want to expose this information).

提交回复
热议问题