473,414 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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
Feb 7 '06 #1
6 1307
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.
Feb 7 '06 #2
The generic solution is to throw an exception.
"use an assertion" is one form of throw an exception.

Feb 7 '06 #3
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
Feb 7 '06 #4

catch( InitError const k )

catch ( Monkey::InitError const k)
Feb 7 '06 #5
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...
Feb 7 '06 #6
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
Feb 9 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: PF | last post by:
Hello, I'm pleased to see activity on this topic as it pains me to write "classmethod" two pages of code after the method definition. However I find the decorators to obfuscate the syntax and...
4
by: Chris | last post by:
Hi, I followed the the aricle http://support.microsoft.com/default.aspx?scid=kb;en-us;321525 and was able to execute a dts package in vb.net. I replaced all the "Console.WriteLine" with "msgbox"....
7
by: Klaus Johannes Rusch | last post by:
Is the following code valid and supported by current implementations? function somename() { this.show = function () { document.write("somename called") } } var somename = new somename();...
8
by: Jan-Ole Esleben | last post by:
Hi! I am new to this list, and maybe this is a stupid question, but I can't seem to find _any_ kind of answer anywhere. What I want to do is the following: I want to insert a class variable...
3
by: hazz | last post by:
The following classes follow from the base class ' A ' down to the derived class ' D ' at the bottom of the inheritance chain. I am calling the class at the bottom, "public class D" from a client...
2
by: twawsico | last post by:
I ran into this while converting some DX C# code to VB.NET (VS 2003), and I'm just curious as to whether this is intended behavior (and if so, where might I read up on it) or more of a bug. This...
0
by: Samuel Zallocco | last post by:
Hi all, I've a problem with PHP5 + PEAR::SOAP. I Have the following 2 script that implements a simple web service: The Server Code running on WinXP + PHP5 + Apache 2.x:...
10
by: Joel | last post by:
Is it true that if we don't specify a default constructor for our class, then the C# compiler provides us with its own that zeroes (or assigns default values) to the data members? I wrote a...
17
by: Jason Doucette | last post by:
I am converting a C-style unit into a C++ class. I have an implementation function that was defined in the .cpp file (so it was hidden from the interface that exists in the .h file). It uses a...
11
by: TinaJones095 | last post by:
Hello I am going to give a program that I have done, but I have to modifiy it, but I need help okay can you help ? Here the program I need help to straighten up below: the Java error is right at...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.