标签:
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
标签:
原文地址:http://www.cnblogs.com/lcchuguo/p/4889823.html