开发者

C# exceptions in debug mode vs real

I always thought that in Visual Studio and C#, an unhandled exception leads invariably to program termination. Now I know I can continue. Also when the application is running in the debug mode, I ca开发者_C百科n "skip" unhandled exceptions while once the program is deployed (or how is it called when you make an executable?) it will crash it?


I think these articles would be useful for you to read:

Exception Handling (MSDN)
Handling and Throwing Exceptions (MSDN)

It's better to grasp the basics then decide what fits best for you.


catch(Exception ex)
{
  #if DEBUG
   Console.WriteLn("oops")
  #else
   throw
  #endif
}


The exception means something unexpected occured. If the application doesn't know how to respond, it would crash.

The reason we have the constructs like try catch finally is to make the application aware of the unforeseen issues and how to react in such cases.

If you implement exception handling properly, your application would always run smoothly. It might come to termination, but even that wouldn't be abrupt.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜