RE: [Dev-C++] Constructors throwing exceptions.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-07-25 22:13:39
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Daniel Glenfield
> Sent: Tuesday, July 23, 2002 3:52 PM
> To: dev...@li...
> Subject: [Dev-C++] Constructors throwing exceptions.
>
>
> Hello all,
> I want my constructors (default, overloaded, and copy) to throw an
> exception if they fail.
>
> 1) How do I test if the constructor has failed?
The usual way.
void somefunc()
{
try
{
A a(1);
// ... Do your job
}
catch(failure)
{
// ...
}
}
> 2) Is it better to create an Exception class to throw
> exception objects,
> rather than throwing strings and integers?
The answer is that it is better to create an hierarchy of exceptions in
large projects. The rest is up to you.
> 3) Where does the catch block go? In the main function after
> the object has
> been created? Or in the constructor body?
You can catch exceptions thrown by other sub-objects during the
construction phase and deal with them locally, or deal with them locally
and rethrow some (or the same) exception.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|