{"id":583,"date":"2011-09-09T08:02:42","date_gmt":"2011-09-09T07:02:42","guid":{"rendered":"http:\/\/www.meadow.se\/wordpress\/?p=583"},"modified":"2011-09-09T08:05:34","modified_gmt":"2011-09-09T07:05:34","slug":"detecting-unhandled-errors-in-asp-net-applications","status":"publish","type":"post","link":"https:\/\/www.meadow.se\/wordpress\/detecting-unhandled-errors-in-asp-net-applications\/","title":{"rendered":"Detecting unhandled errors in ASP.Net applications"},"content":{"rendered":"<p>For my own reference, here&#8217;s how to detect unhandled exceptions in Global.asax:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nprotected void Application_Error(object sender, EventArgs e)\r\n{\r\n  \/\/ Log error\r\n  Exception ex = Server.GetLastError().GetBaseException();\r\n  string msg = String.Format(&quot;Ohanterat fel!\\r\\nAdress: {0}\\r\\nFelmeddelande: {1}&quot;, Request.Url, ex.Message);\r\n  LogHelper.Error(msg, ex);\r\n\r\n  Server.ClearError();\r\n\r\n  \/\/ Display simple error page\r\n  Response.Write(&quot;Ett ov\u00e4ntat fel har intr\u00e4ffat...\\r\\n&quot;);\r\n  Response.Write(&quot;&lt;br\/&gt;\\r\\n&lt;pre&gt;\\r\\n&quot;);\r\n  Response.Write(ex.ToString());\r\n  Response.Write(&quot;&lt;br\/&gt;\\r\\n&lt;\/pre&gt;\\r\\n&quot;);\r\n  Response.End();\r\n}\r\n<\/pre>\n<p>We mostly do it like this, if you have a better suggestion, please post a comment \ud83d\ude42<\/p>\n<p>\/Emil<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For my own reference, here&#8217;s how to detect unhandled exceptions in Global.asax: protected void Application_Error(object sender, EventArgs e) { \/\/ Log error Exception ex = Server.GetLastError().GetBaseException(); string msg = String.Format(&quot;Ohanterat fel!\\r\\nAdress: {0}\\r\\nFelmeddelande: {1}&quot;, Request.Url, ex.Message); LogHelper.Error(msg, ex); Server.ClearError(); \/\/ Display simple error page Response.Write(&quot;Ett ov\u00e4ntat fel har intr\u00e4ffat&#8230;\\r\\n&quot;); Response.Write(&quot;&lt;br\/&gt;\\r\\n&lt;pre&gt;\\r\\n&quot;); Response.Write(ex.ToString()); Response.Write(&quot;&lt;br\/&gt;\\r\\n&lt;\/pre&gt;\\r\\n&quot;); Response.End(); } We mostly <a class=\"more-link\" href=\"https:\/\/www.meadow.se\/wordpress\/detecting-unhandled-errors-in-asp-net-applications\/\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[94,42,43],"_links":{"self":[{"href":"https:\/\/www.meadow.se\/wordpress\/wp-json\/wp\/v2\/posts\/583"}],"collection":[{"href":"https:\/\/www.meadow.se\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.meadow.se\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.meadow.se\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.meadow.se\/wordpress\/wp-json\/wp\/v2\/comments?post=583"}],"version-history":[{"count":5,"href":"https:\/\/www.meadow.se\/wordpress\/wp-json\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":607,"href":"https:\/\/www.meadow.se\/wordpress\/wp-json\/wp\/v2\/posts\/583\/revisions\/607"}],"wp:attachment":[{"href":"https:\/\/www.meadow.se\/wordpress\/wp-json\/wp\/v2\/media?parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.meadow.se\/wordpress\/wp-json\/wp\/v2\/categories?post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.meadow.se\/wordpress\/wp-json\/wp\/v2\/tags?post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}