{"id":3983,"date":"2013-06-26T07:00:00","date_gmt":"2013-06-26T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/06\/26\/the-default-error-mode-seterrormode-is-not-zero\/"},"modified":"2013-06-26T07:00:00","modified_gmt":"2013-06-26T07:00:00","slug":"the-default-error-mode-seterrormode-is-not-zero","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130626-00\/?p=3983","title":{"rendered":"The default error mode (SetErrorMode) is not zero"},"content":{"rendered":"<p><P>\nA customer put the following code at the start of their program:\n<\/P>\n<PRE>\n\/\/ If this assertion fires, then somebody else changed the error mode\n\/\/ and I just overwrote it with my error mode.\nASSERT(SetErrorMode(SEM_FAILCRITICALERRORS) == 0);\n<\/PRE>\n<P>\nThe customer wanted to know whether it was a valid assumption\nthat the initial error mode for a process is zero.\n<\/P>\n<P>\nNo it is not, and this is called out in the documentation for\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/ms680621\">\n<CODE>Set&shy;Error&shy;Mode<\/CODE><\/A>:\n<\/P>\n<BLOCKQUOTE CLASS=\"q\">\n<P>\n<B>Remarks<\/B>\n<\/P>\n<P>\nEach process has an associated error mode that indicates\nto the system how the application is going to respond to serious errors.\n<FONT COLOR=\"red\">\nA child process inherits the error mode of its parent process.<\/FONT>\n<\/P>\n<\/BLOCKQUOTE>\n<P>\nThe assumption that the initial error mode is zero is therefore false.\n<\/P>\n<P>\nThere&#8217;s another error in the above code:\nThe call to\n<CODE>Set&shy;Error&shy;Mode<\/CODE> is placed inside an assertion.\nThis means that in the retail build, the call <I>disappears<\/I>.\nThe debug build has the error mode set to\n<CODE>SEM_FAIL&shy;CRITICAL&shy;ERRORS<\/CODE>,\nbut the retail build has the default error mode.\nThey are\n<A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2006\/08\/15\/701130.aspx\">\nchanging the semantics in the debug build<\/A>,\nand are headed down the slippery slope that leads to them being forced\nto deploy the debug version of the program into production\nbecause that&#8217;s the only build that works.\n<\/P>\n<P>\nUnfortunately, they may have already reached that point,\nbecause the customer asked,\n&#8220;Is it possible for the user to set the default error\ncode to something other than zero,\nin which case this assertion <U>would crash the client<\/U>?&#8221;\n(Emphasis mine.)\n<\/P>\n<P>\n<B>Bonus chatter<\/B>:\nNote that you can override error mode inheritance\nby passing the\n<CODE>CREATE_DEFAULT_ERROR_MODE<\/CODE>\nflag to the <CODE>Create&shy;Process<\/CODE> function.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer put the following code at the start of their program: \/\/ If this assertion fires, then somebody else changed the error mode \/\/ and I just overwrote it with my error mode. ASSERT(SetErrorMode(SEM_FAILCRITICALERRORS) == 0); The customer wanted to know whether it was a valid assumption that the initial error mode for a [&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-3983","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer put the following code at the start of their program: \/\/ If this assertion fires, then somebody else changed the error mode \/\/ and I just overwrote it with my error mode. ASSERT(SetErrorMode(SEM_FAILCRITICALERRORS) == 0); The customer wanted to know whether it was a valid assumption that the initial error mode for a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3983","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=3983"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3983\/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=3983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=3983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=3983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}