Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error - "throws different exceptions" in C++

I am getting an error that tells me

error: declaration of 'virtual FXHost::~FXHost()' throws different exceptions
error: than previous declaration 'virtual FXHost::~FXHost() throw ()'

I am not sure how to begin solving this, I have never encountered this before.

in my .h I have:

public:
    virtual                         ~FXHost() throw();

in my .cpp I have:

FXHost::~FXHost()
{
   gHost = NULL;
}

Pointers appreciated.

like image 524
ator Avatar asked Dec 29 '22 08:12

ator


2 Answers

The throw() at the end of a function declaration is an exception specification. It means the function never throws an exception. This cannot be overridden (only restricted further) in derived classes, hence the error.

Since your implementation doesn't throw exceptions itself, all you need is adding throw() to your destructor declaration.

See here why you should (not) use this (mis)feature of C++

like image 75
jpalecek Avatar answered Jan 08 '23 06:01

jpalecek


FXHost::~FXHost() throw()
{
   gHost = NULL;
}

Your implementation has to be at least as restrictive in terms of exception throwing as its declaration.

like image 44
haffax Avatar answered Jan 08 '23 06:01

haffax