 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Steffen Liersch Guest
|
Posted: Fri Nov 28, 2003 1:56 pm Post subject: Cannot create object derivated from SysUtils::Exception |
|
|
Hello!
If I have the following class,
#include <SysUtils.hpp>
class SampleException : public Exception
{
};
I cannot throw an exception using the statement
throw SampleException("Error");
The compiler message is that there is not standard constructor available,
but I think it should be available because SampleException is derivated from
Exception and there is an constructor for type AnsiString. What's the
problem?
Thank you in advance,
Steffen Liersch
|
|
| Back to top |
|
 |
Giuliano Guest
|
Posted: Fri Nov 28, 2003 11:34 pm Post subject: Re: Cannot create object derivated from SysUtils::Exception |
|
|
On Fri, 28 Nov 2003 14:56:22 +0100, "Steffen Liersch"
<steffen_liersch_pub (AT) gmx (DOT) de> wrote:
| Quote: | Hello!
If I have the following class,
#include
class SampleException : public Exception
{
};
I cannot throw an exception using the statement
throw SampleException("Error");
The compiler message is that there is not standard constructor available,
but I think it should be available because SampleException is derivated from
Exception and there is an constructor for type AnsiString. What's the
problem?
Thank you in advance,
Steffen Liersch
|
You have to call the base class contructor, e.g.
class SampleException : public Exception
{
public:
SampleException( AnsiString Text )
: Exception( Text ) {}
};
HTH
Regards
Giuliano
|
|
| Back to top |
|
 |
Ivan Johansen Guest
|
Posted: Fri Nov 28, 2003 11:42 pm Post subject: Re: Cannot create object derivated from SysUtils::Exception |
|
|
Steffen Liersch wrote:
| Quote: | #include
class SampleException : public Exception
{
};
I cannot throw an exception using the statement
throw SampleException("Error");
The compiler message is that there is not standard constructor available,
but I think it should be available because SampleException is derivated from
Exception and there is an constructor for type AnsiString. What's the
problem?
|
You didn't write any constructors for SampleException. The compiler will
supply a default constructor and a copy constructor. If you want any
other constructors you must write them yourself. I guess what you want
is this:
class SampleException : public Exception
{
public:
SampleException(const AnsiString &Str)
: Exception(Str) {}
};
Ivan Johansen
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Nov 29, 2003 12:24 am Post subject: Re: Cannot create object derivated from SysUtils::Exception |
|
|
"Steffen Liersch" <steffen_liersch_pub (AT) gmx (DOT) de> wrote
| Quote: | I cannot throw an exception using the statement
throw SampleException("Error");
|
Works fine every time I've ever used custom exception classes like that.
| Quote: | The compiler message is that there is not standard constructor available
|
You didn't provide any constructor for your class. You need to do that, ie:
class SampleException : public Exception
{
public:
__fastcall SampleException(const AnsiString Msg) : Exception(Msg) {}
};
| Quote: | but I think it should be available because SampleException is derivated
from
Exception and there is an constructor for type AnsiString.
|
For the Exception class, yes. Not for the SampleException class, no. In
C++, every class must provide its own constructors, they are not inherited
like they are in Delphi.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|