473,395 Members | 1,526 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,395 software developers and data experts.

what to do when instance of class fails to initialize ?

Hello !

As you might have guessed, I'm one of those newbie-types, comming here,
asking questions and stuff...

Very specific question, it's probably a bit basic so forgive me if it's
stupid to ask...

If I have an __init__ for a class and the initialisation can't go through
(example: missing or wrong arguments), how do I return an error to the
caller (from main() function)? When I do a return statement in the
__init__ it says __init__ should return None... I can stop the flow with
raise 'BlahBlah'. But then the program exits.

What is the nice way to do this ?

Tnx,

--
Tom Van den Brandt
I try...
Jul 18 '05 #1
2 1541
Tnx guys,

Problem solved...
Jul 18 '05 #2
Tom Van den Brandt wrote:
If I have an __init__ for a class and the initialisation can't go through
(example: missing or wrong arguments), how do I return an error to the
caller (from main() function)? When I do a return statement in the
__init__ it says __init__ should return None... I can stop the flow with
raise 'BlahBlah'. But then the program exits.

What is the nice way to do this ?


catch the exception:

http://www.python.org/doc/current/tut/node10.html:
http://www.python.org/doc/current/ref/try.html

</F>

<!-- (the eff-bot guide to) the python standard library (redux):
http://effbot.org/zone/librarybook-index.htm
-->


Jul 18 '05 #3

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
1
by: Gerry Sutton | last post by:
Hi All! I have noticed a strange behavior when using a constant identifier to initialize an instance list variable in a base class and then trying to modifying the list in subclasses by using...
9
by: Bob Rock | last post by:
Hello, I was wondering when should static constructors be defined or are they even required??? Also, when are they implicitly called??? Bob Rock
0
by: lkrubner | last post by:
At the top of one class I declare a security object: var $securityObject = null; In the constructor, I initialize a bunch of member objects. Because I've had trouble with the security object,...
8
by: imutate | last post by:
I have a std::vector with each element being a class, I push_back elements and then store values in the class object, later I look at these objects and the values are null. In essence: class...
10
by: Simon Brooke | last post by:
The DOM API has included public Node importNode(Node,boolean) as a method of the Document interface for a long time. Does anything actually implement it? Xerces 2 is giving me: ...
6
by: r.z. | last post by:
They should be initialized before any instance is created. I have no idea in which file, in which place should I put their initialization code to be sure they are initialize only once, before any...
2
by: titan.nyquist | last post by:
I need to initialize data to be stored in a static class (for all my code to see), but I'm lost on how to do so. If I use the class constructor, what if it fails? I am reading it information...
6
by: Jack | last post by:
I have a set of functions to wrap a library. For example, mylib_init() mylib_func() mylib_exit() or handle = mylib_init() mylib_func(handle)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.