What does it mean when my program exits with the message "This application has requested the Runtime to terminate it in an unusual way"?


You're running your program, and then it suddenly exits with the message This application has requested the Runtime to terminate it in an unusual way. What happened?

That message is printed by the C runtime function abort, the same function that also causes your program to terminate with exit code 3.

Your program might call abort explicitly, or it might end up being called implicitly by the runtime library itself.

The C++ standard spells out the conditions under which terminate is called, and it's quite a long list, so I won't bother repeating them here. Consult your favorite copy of the C++ standard for details. (The most common reason is throwing an unhandled exception.)

Comments (21)
  1. Anonymous says:

    I'd wager that the most common reason that std::terminate gets called is when an exception is thrown but never caught.

    Also note that _set_abort_behavior (msdn.microsoft.com/…/e631wekh%28v=VS.100%29.aspx) can be used to modify what calling abort() does, e.g. if you want your program not to display that message box when an assertion fails.

  2. Mordachai says:

    It's also pretty common to generate an exception while catching one.  This one comes up a lot if you're not savvy enough to know not to put throwing code in your destrcutors.

  3. SimonRev says:

    @Steve — I thought that destructors should never throw was C++ 101 material.

  4. Anonymous says:

    @SimonRev: Huh?  IIRC they didn't even cover exceptions in my basic C++ class.

  5. DWalker59 says:

    That error message sounds…  creepy somehow.  When a program asks another program to do something to it, in an unusual way…  I wonder what those programs have been up to in their spare time?   :-)

  6. @Mason Wheeler:

    You want your money back. That was C 101 class.

  7. Anonymous says:

    @alegr1: Nah, I'm pretty content with what I learned, actually.  I learned a lot about programming in general, and object-oriented programming techniques, from that class.  And most important of all, I learned that I never under any circumstances want to touch the C++ language again for the rest of my life.  That lesson alone was worth the tuition cost. ;)

  8. Mordachai says:

    Lol – I hope that "never throw in your dtor" is a lesson somewhere in the early curriculum of C++, but probably not the first intro class ever!  Probably in the first class that introduces the concepts of exception handling, however.

    But maybe I'm just showing my age in worrying that folks still don't necessarily know that.

  9. Anonymous says:

    @Mason Wheeler:

    Why? I don't see anything problematic. Unless you mean it is bit more difficult as it lets you solve problems many ways… (templates anybody? ;) )

  10. Anonymous says:

    I have been programming C++ for years and I have never even touched exceptions for the most part.

  11. Anonymous says:

    My opinion on exceptions is that they are indistinguishable from invisible conditional goto's inserted in every function (or operator) call in your code. That might not be so terribly bad, but they are goto's targeting locations in your code that are extremely context dependent and difficult to determine.

  12. hankdane says:

    Ray, throws are not goto's.  Sure, they both change the instruction pointer, but in this, throws are in common with, say, switch statements or function calls.  

    All you have spelled out is that error handling is tricky.  Yes, and exceptions is one of your tools to deal with it, and a particularly powerful one.

  13. Anonymous says:

    I can see users getting confused with this message because it doesn't sound like an error message (it is worded more in the "it's a feature, not a bug" form.) Better might be the usual "Abnormal termination" that other runtimes use, because it sounds scarier, so users will probably report it more often!

    Regarding exceptions, they didn't exist in C++ when I first learned the language (I started learning with Turbo C++ 1.0.) I seem to recall that my first real exposure to exceptions was with Java 1.1, quite a while later. It's a different mindset while programming, and I still admit to not using exceptions as they were probably intended; it just feels too weird not to check for error conditions!

  14. Anonymous says:

    Wait, assert? I've never seen that error message caused by an assert.  I thought that error occurred with manifest config errors.  I've rarely seen it.

  15. I suppose "You cursed brat! Look what you've done! I'm melting! melting! Oh, what a world! What a world! Who would have thought a good little girl like you could destroy my beautiful wickedness? Oooooh, look out! I'm going! Oooooh! Ooooooh!" would have generated too many support calls.

  16. Anonymous says:

    To all the people surprised to hear that throwing from a destructor is a bug: doing that is a clear-cut consequence of a more general principle in programming, that you don't signal error on a cleanup path. That even goes for a language without exceptions (e.g. C). So you should revise your understanding, not of C, really, but of programming in general.

    @Jonathan Wilson: you can "not touch exceptions for the most part" in C++ only if you're writing exception-unsafe code. That's because virtually everything in C++ throws. STL throws. MFC throws. ATL throws. boost throws. Even simplest of things like "string s = s1+s2" throw. So I can only hope that your code terminates immediately when any exception is thrown in it (because otherwise, it's doing more bad than good when that happens).

  17. Anonymous says:

    About throwing in the destructors, there's an interesting blog post:

    "Clean-up functions can't fail because, well, how do you clean up from a failed clean-up?"

    blogs.msdn.com/…/7011066.aspx

  18. Anonymous says:

    @Goran: "So I can only hope that your code terminates immediately when any exception is thrown in it". Well, yes it does (because  that's what ignored exceptions do), byt only if assuming the program does get compiled with exception support. Many don't. And guess what, string s= s1+s2 crashes then with an access violation, if OOM.

  19. Anonymous says:

    @Maurits: You can never have too many Fight Club or Wizard of OZ references in a program!

  20. GregM says:

    "Wait, assert? I've never seen that error message caused by an assert.  I thought that error occurred with manifest config errors.  I've rarely seen it."

    That's "assert", not "ASSERT", they're different.

  21. Anonymous says:

    i asked this question on Stackoverflow 2 weeks before Raymond gave another answer. (What is the cause of “This application has requested the Runtime to terminate it in an unusual way”?)

Comments are closed.