{"id":228,"date":"2020-09-01T08:42:34","date_gmt":"2020-09-01T07:42:34","guid":{"rendered":"http:\/\/blog.c-hase.de\/?p=228"},"modified":"2020-09-01T08:42:34","modified_gmt":"2020-09-01T07:42:34","slug":"genaue-try-catch-exception","status":"publish","type":"post","link":"http:\/\/blog.c-hase.de\/?p=228","title":{"rendered":"genaue try catch exception"},"content":{"rendered":"<blockquote class=\"wp-embedded-content\" data-secret=\"XcL758zXCg\"><p><a href=\"https:\/\/stackify.com\/csharp-exception-handling-best-practices\/\">C# Exception Handling Best Practices<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;C# Exception Handling Best Practices&#8221; &#8212; Stackify\" src=\"https:\/\/stackify.com\/csharp-exception-handling-best-practices\/embed\/#?secret=AB0NL0HwXq#?secret=XcL758zXCg\" data-secret=\"XcL758zXCg\" width=\"584\" height=\"329\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>durch mehrere catch- blocks k\u00f6nnen (zuerst) speziellere Exceptions behandelt werden , eine geauere auswahl kann durch when erzielt werden.<\/p>\n<pre class=\"wp-block-preformatted prettyprint\">WebClient wc = null;\r\ntry\r\n{\r\n   wc = new WebClient(); \/\/downloading a web page\r\n   var resultData = wc.DownloadString(\"http:\/\/google.com\");\r\n}\r\ncatch (WebException ex) when (ex.Status == WebExceptionStatus.ProtocolError)\r\n{\r\n   \/\/code specifically for a WebException ProtocolError\r\n}\r\ncatch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound)\r\n{\r\n   \/\/code specifically for a WebException NotFound\r\n}\r\ncatch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.InternalServerError)\r\n{\r\n   \/\/code specifically for a WebException InternalServerError\r\n}\r\nfinally\r\n{\r\n   \/\/call this if exception occurs or not\r\n   wc?.Dispose();\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>C# Exception Handling Best Practices durch mehrere catch- blocks k\u00f6nnen (zuerst) speziellere Exceptions behandelt werden , eine geauere auswahl kann durch when erzielt werden. WebClient wc = null; try { wc = new WebClient(); \/\/downloading a web page var resultData &hellip; <a href=\"http:\/\/blog.c-hase.de\/?p=228\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-228","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts\/228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=228"}],"version-history":[{"count":1,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions"}],"predecessor-version":[{"id":229,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions\/229"}],"wp:attachment":[{"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}