Correct behavior for failure during __init__() 
Author Message
 Correct behavior for failure during __init__()

Howdy,

I'm wrapping a C library with with python and swig. I'm defining a class
like this (wLib) is the wrapped C library:

   import wLib

   class ddId:
       def __init__(self, arg1, arg2):
           t1 = wLib.createObj(arg1, arg2)
           if t1:
               self.Id = t1
           else:
               NOW WHAT?

It is possible that the call to wLib.createObj does not succeed. In this
case it is not clear to me what I should do where I've marked "NOW WHAT?"
in the code above.

Any suggestions and/or pointers will be greatly appreciated.

Thanks,

Jeff.



Mon, 03 Nov 2003 06:47:46 GMT  
 Correct behavior for failure during __init__()


Quote:

>I'm wrapping a C library with with python and swig. I'm defining a class
>like this (wLib) is the wrapped C library:

>   import wLib

>   class ddId:
>       def __init__(self, arg1, arg2):
>           t1 = wLib.createObj(arg1, arg2)
>           if t1:
>               self.Id = t1
>           else:
>               NOW WHAT?

>It is possible that the call to wLib.createObj does not succeed. In this
>case it is not clear to me what I should do where I've marked "NOW WHAT?"
>in the code above.

Generally, the answer is to raise an exception (presuming this situation
means that an error has occurred that makes the new instance unusable).
For example, the open() function returns a file object; if open() fails,
it raises an exception (usually an IOError):

Quote:
>>> open('foo')

Traceback (innermost last):
  File "<stdin>", line 1, in ?
IOError: [Errno 2] No such file or directory: 'foo'
--

Androgynous poly {*filter*} vanilla {*filter*} het Pythonista   http://www.*-*-*.com/
Hugs and backrubs -- I break Rule 6

"It's such a fine line between stupid and clever."  --David St. Hubbins



Mon, 03 Nov 2003 07:28:22 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Correct behavior for failure during __init__()

2. Test failures in init.test (init-4.6)

3. Tcl8.3 Problem: Can't find correct init.tcl file

4. Failure checking while in init/new methods

5. List Init Behavior

6. VM Integrity failure during Asort()

7. correct behavior

8. Is this behavior correct?

9. the correct behavior

10. correct Numeric behavior?

11. Correct behavior for file-write-date?

12. Tk4.0b: please correct the binding behavior

 

 
Powered by phpBB® Forum Software