TITLE: uncaught_exception() considered flawed (Newsgroups: comp.std.c++, 10 Nov 98) DEROCCO: "Paul D. DeRocco" wrote: > > [code snipped] > > > > Nice, but it still has the problem, true of all things that use > > uncaught_exception(), that it may be called while unwinding the stack on > > behalf of some unrelated exception that it doesn't have anything to do > > with, and be fooled into thinking it can't do something that it really > > can, or should do something that it mustn't, etc. ABRAHAMS: abrahams@motu.com > With all due respect, it sounds like you are appealing to vague fears here. > Please justify your claim with an example. BONNARD: Valentin Bonnard I agree that current uncaught_exception() specificatons are broken: this function indicates if there is an active exception somewhere in the system, not if we are currently doing the stack walkback: struct E { ~E () { std::cout << std::uncaught_exception() << std::endl; } E x; throw 0; correctly prints true but struct F { ~F () { E e; } } f; throw 0; incorrectly prints true ! (we aren't doing a walkback because of exceptions, we are normally exiting a function). Note that struct F { E e; /*~F () {} */ } f; throw 0; correctly prints true. uncaught_exception() breaks basic functionnal decomposition; a function does its job, honors its exception spec, ect, it doesn't have to know that its caller is already playing with exceptions. uncaught_exception() should indicate if we are destroyed because of a walk-back.