destroy object

neversleep

Newcomer
Joined
Feb 21, 2003
Messages
6
Location
Sweden
Hi

Is it possible for an object to destroy itself?

In the constructor in my class i have a method call that builds the object. But if anything goes wrong here I don't want the object to be created. How do I acomplish that?
 
You can't, in the constructor. If there is a chance the object creation might fail, use a static public function to instantiate the class and make the constructor private, like the Graphics class. You can then return null (Nothing in VB) if it fails.
 
Thanks divil, nice solution...did it in another way though. If anyone's interested;

If the object doesn't succed in the creation it throws an exception

try
myObject obj = new object()
'creation ok
catch
'no object was created

end try
 
Back
Top