neversleep Posted February 28, 2003 Posted February 28, 2003 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? Quote
*Gurus* divil Posted February 28, 2003 *Gurus* Posted February 28, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
neversleep Posted February 28, 2003 Author Posted February 28, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.