标签:c#
在 C# 6.0 新功能裹的异常处理,有两个改进:try { WebRequest webRequest = WebRequest.Create("http://www.csdn.net"); WebResponse response = await webRequest.GetResponseAsync(); // ... } catch (WebException exception) { await WriteErrorToLog(exception); }
try { DoSomeHttpRequest(); } catch (System.Web.HttpException e) if (e.GetHttpCode() == 400) { WriteLine("Not Found"); } catch (System.Web.HttpException e) if (e.GetHttpCode() == 500) { WriteLine("Internal Server Error"); } catch { WriteLine("Generic Error"); }
try { DoSomeHttpRequest(); } catch (System.Web.HttpException e) { switch (e.GetHttpCode()) { case 400: WriteLine("Bad Request"); case 500: WriteLine("Internal Server Error"); default: WriteLine("Generic Error"); } }
C# 6.0 (C# vNext) 新功能之:Exception-Handling Improvements
标签:c#
原文地址:http://blog.csdn.net/kendo3065/article/details/40085319