{"id":38323,"date":"2004-07-27T07:00:00","date_gmt":"2004-07-27T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/07\/27\/disabling-the-program-crash-dialog\/"},"modified":"2004-07-27T07:00:00","modified_gmt":"2004-07-27T07:00:00","slug":"disabling-the-program-crash-dialog","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040727-00\/?p=38323","title":{"rendered":"Disabling the program crash dialog"},"content":{"rendered":"<p>\nIf you don&#8217;t want your program to display the standard\ncrash dialog,\nyou can disable it by setting the\nSEM_NOGPFAULTERRORBOX\nflag in the process error mode.\n<\/p>\n<p>\nThe simple-minded way is just to do\n<\/p>\n<pre>\nSetErrorMode(SEM_NOGPFAULTERRORBOX);\n<\/pre>\n<p>\nbut this overwrites the previous error mode rather than augmenting it.\nIn other words, you inadvertently turned off the other error modes!\n<\/p>\n<p>\nUnfortunately, there is no GetErrorMode function,\nso you have to do a double-shuffle.\n<\/p>\n<pre>\nDWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX);\nSetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX);\n<\/pre>\n<p>\nThis sets the new error mode (possibly disabling some other error\nmodes that had been set) and saves the previous mode.  Then it\nsets the error mode the right way, adding the SEM_NOGPFAULTERRORBOX\nflag to the existing error modes.\n<\/p>\n<p>\nMerging with existing error modes is important.\nFor example, the previous error mode may have included\nSEM_NOALIGNMENTFAULTEXCEPT.\nIf you casually turned that off, then the program would not longer\nreceive automatic alignment fault fixups and will start crashing.\n<\/p>\n<p>\n(But if you read the documentation, you&#8217;ll see that\nSEM_NOALIGNMENTFAULTEXCEPT is special:  The system won&#8217;t let you turn\nit off once it&#8217;s been turned on.  Why?  <strong>Because too many\npeople were already making this mistake<\/strong>.\nI remember before this special rule was introduced.\nPrograms were crashing left and right because they\ndidn&#8217;t do the double-set shuffle above; as a result, they\nstarted crashing on alignment faults.\nSo the special rule had to be added.\nWelcome to the world of compatibility, where it\nis the operating system&#8217;s duty to cover for other people&#8217;s mistakes.\nMind you, the design of\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/debug\/base\/seterrormode.asp\">\nthe SetErrorMode function<\/a> makes this mistake\na very easy one to commit.)\n<\/p>\n<p>\nNote that the error mode is a process-wide setting, not a per-thread\nsetting.  This means that manipulating the process error mode is\nnot something you should do lightly, since it may have unintended\nconsequences for other threads (which you might not have control over).\nFor safety&#8217;s sake, a program should set its error mode when it starts\nup and not mess with it thereafter.\n<\/p>\n<p>\nOf course, if you disable the crash dialog, then\n<a href=\"http:\/\/weblogs.asp.net\/larryosterman\/archive\/2004\/06\/01\/145627.aspx\">\nyou also miss out on the opportunity to retrieve crash reports collected\nby Windows Error Reporting<\/a> so you can see where your program is\ncrashing in the real world.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you don&#8217;t want your program to display the standard crash dialog, you can disable it by setting the SEM_NOGPFAULTERRORBOX flag in the process error mode. The simple-minded way is just to do SetErrorMode(SEM_NOGPFAULTERRORBOX); but this overwrites the previous error mode rather than augmenting it. In other words, you inadvertently turned off the other error [&hellip;]<\/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-38323","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>If you don&#8217;t want your program to display the standard crash dialog, you can disable it by setting the SEM_NOGPFAULTERRORBOX flag in the process error mode. The simple-minded way is just to do SetErrorMode(SEM_NOGPFAULTERRORBOX); but this overwrites the previous error mode rather than augmenting it. In other words, you inadvertently turned off the other error [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/38323","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=38323"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/38323\/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=38323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=38323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=38323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}