Class execution



 DEVELOP > c-Plus-Plus > Class execution

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Riaan"
Date: 06 Feb 2006 12:35:24 AM
Object: Class execution
Hi Everybody,
How do I stop my class of being used after certain init functions failed in
my constructor ?
Be Good
--
Riaan Bekker
.

User: "Tomás"

Title: Re: Class execution 07 Feb 2006 03:12:31 AM
Riaan posted:

Hi Everybody,

How do I stop my class of being used after certain init functions
failed in my constructor ?

Be Good

class Monkey {
public:
class InitError {}; // Just a dummy type
Monkey(int a)
{
if ( !a )
{
throw InitError();
}
}
};
int main()
{
try {
Monkey ape;
}
catch( InitError const k )
{
}
}
Unchecked code, may contain errors/bugs.
-Tomás
.
User: "Tomás"

Title: Re: Class execution 07 Feb 2006 03:16:56 AM

catch( InitError const k )

catch ( Monkey::InitError const k)
.
User: "Ben Pope"

Title: Re: Class execution 07 Feb 2006 04:00:24 AM
Tomás wrote:

catch( InitError const k )



catch ( Monkey::InitError const k)

catch ( Monkey::InitError const& k)
Ben Pope
--
I'm not just a number. To many, I'm known as a string...
.



User: "Ian Collins"

Title: Re: Class execution 06 Feb 2006 10:01:37 PM
Riaan wrote:

Hi Everybody,

How do I stop my class of being used after certain init functions failed in
my constructor ?

Call abort or use an assert. There is no other generic way.

Be Good

I'll try :)
--
Ian Collins.
.

User: "improgrammer"

Title: Re: Class execution 06 Feb 2006 11:19:30 PM
The generic solution is to throw an exception.
"use an assertion" is one form of throw an exception.
.
User: "Rein Anders Apeland"

Title: Re: Class execution 09 Feb 2006 01:47:03 PM
improgrammer wrote:

The generic solution is to throw an exception.
"use an assertion" is one form of throw an exception.

AFAIK 'using an assertion' is NOT a form of 'throwing an exception'.
Exceptions can be caught, assertions cannot. Assertions will abort your
program if the fail.
-Rein
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER