{"id":98925,"date":"2018-06-06T07:00:00","date_gmt":"2018-06-06T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=98925"},"modified":"2019-03-13T00:41:37","modified_gmt":"2019-03-13T07:41:37","slug":"20180606-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20180606-00\/?p=98925","title":{"rendered":"The unhandled exception filter is the responsibility of the process; don&#8217;t change it without permission"},"content":{"rendered":"<p>A customer developed an Office add-in and wanted to intercept all unhandled exceptions so that they could collect crash dumps, capture stack traces, and so on. To do this, they used the <code>Set&shy;Unhandled&shy;Exception&shy;Filter<\/code> function to register their custom unhandled exception handler to capture crash dumps and stack traces. <\/p>\n<p>The customer reported that this technique was successful in earlier versions of Office, but stopped working starting in Office 2013. (They didn&#8217;t test Office 2010.) Their custom unhandled exception handler is no longer being called. <\/p>\n<p>The customer wanted to know if there were any known circumstances where the <code>Set&shy;Unhandled&shy;Exception&shy;Filter<\/code> function would stop working, and what workarounds were available, even if it means abandoning their current strategy and getting their crash dumps some other way. <\/p>\n<p>The unhandled exception filter is a process-wide resource, and therefore the process is the one who makes the decision what unhandled exception filter they want. A DLL is a guest in the host process, and common courtesy says that guests don&#8217;t cancel the homeowner&#8217;s insurance policy and replace it with their own. <\/p>\n<p>Besides, imagine what would happen if <i>two<\/i> plug-ins wanted to replace the unhandled exception filter. (Bonus: And then one of those plug-ins was unloaded.) <\/p>\n<p>The Office team discovered that large numbers of add-ins were (either intentionally or inadvertently) corrupting the process-wide unhandled exception filter. This meant that crashes were no longer being routed through Office&#8217;s own unhandled exception filter. Not only were none of the crashes in Office being reported through Windows Error Reporting, users were losing data because Office&#8217;s custom unhandled exception filter was not getting a chance to attempt document recovery before the process finally went away. <\/p>\n<p>To work around rogue DLLs replacing the unhandled exception filter, Office detours the <code>Set&shy;Unhandled&shy;Exception&shy;Filter<\/code> function. <\/p>\n<p><a HREF=\"https:\/\/groups.google.com\/d\/msg\/microsoft.public.office.developer.com.add_ins\/tv4nMiaHcJY\/kS92bPNrHhsJ\">This answer from Office developer support<\/a> confirms the above discussion and further suggests a workaround: Register your plug-in with <a HREF=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb513641(v=vs.85).aspx\">Windows Error Reporting<\/a>. Microsoft&#8217;s back-end error reporting service (known as Watson, not the same as <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20051114-00\/?p=33353\">Dr. Watson<\/a>). All the crashes received by the Watson service are analyzed, and if the analysis concludes that your plug-in was responsible for the problem, the crash dump will be made available to you. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s only common courtesy.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-98925","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>It&#8217;s only common courtesy.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/98925","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=98925"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/98925\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=98925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=98925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=98925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}