what to do when instance of class fails to initialize ?

T

Tom Van den Brandt

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,
 
F

Fredrik Lundh

Tom said:
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
-->
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,091
Messages
2,570,605
Members
47,225
Latest member
DarrinWhit

Latest Threads

Top