This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Terminate called after throwing an instance of...


On Mon, Sep 5, 2011 at 3:54 AM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 5 September 2011 05:13, Jeffrey Walton <noloader@gmail.com> wrote:
>> On Sun, Sep 4, 2011 at 6:50 PM, Jeffrey Walton <noloader@gmail.com> wrote:
>>> Hi All,
>>>
>>> I'm seeing the following on a negative test case:
>>>
>>> ? ?terminate called after throwing an instance of
>>> ? ?'esapi::NoSuchAlgorithmException'
>>> ? ? ?what(): ?Algorithm 'Foo' is not supported
>>>
>>> Any ideas on what might cause the exception to pass uncaught? I am
>>> familiar with http://gcc.gnu.org/faq.html#dso.
>>>
>>> [SNIP]
>>
>> Found it.... MessageDigest md1("Foo") uses 'createInstance(...)' in a
>> PIMPL. However, createInstance(...) [incorrectly] declared it throws a
>> "InvalidArgumentException". In reality, the function throws a
>> "NoSuchAlgorithmException".
>>
>> Visual Studio ran fine because MSVC ignores the exception
>> specification (http://msdn.microsoft.com/en-us/library/wfa0edys%28v=VS.90%29.aspx).
>>
>> I'm running with -Wall, -Wextra, which did not help me. Would anyone
>> know the warning I am looking for? I did not see it at
>> http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html.
>
> There's no such warning, C++ exception specifications are not
> statically checked, ever. ? C++ is not Java.
>
> The only good exception specification is throw() (renamed noexcept in
> C++11), best practice is not to use non-empty exception specs. ?Pretty
> much the only effect non-empty specs have is to cause unwanted
> terminations, as you've discovered, and they're deprecated in C++11.
> If you want to document what exceptions can be thrown, use a comment.
> If it's wrong you won't terminate immediately.
>
> http://www.gotw.ca/publications/mill22.htm
As always, thanks.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]