Handling failure during custom class instantiation?

I’ve been digging through help files and searching here for a couple of hours and I can’t find the answer to what must be a fairly basic question.

I have a custom class. When I instantiate an object of that class it is possible that the object will be invalid due to an error in the parameters being passed. I would like to catch and handle that case in the New subroutine by leaving the object as Nothing. I have tried going about this a number of ways, such as Set Me = Nothing and Delete Me, but these don’t work.

How can I prevent my New routine from creating an object? Or is there a better way of handling this?

Thank you.

Subject: Handling failure during custom class instantiation?

You should be able to throw an error in the new function just like any other function but it is not usually good practice to throw an error in a constuctor. If you need to throw an error then initialize code could be placed in an Intialize function after you instantiate the object.

I don’t think you would be able to set the object to nothing or null. I can see where that would be bad practice too.

Subject: RE: Handling failure during custom class instantiation?

Part of the problem is that I’m trying to write an error handling library, and the last thing I want it to do is pass an error back to the code that calls it. I suppose maybe I should just create an IsValid flag and have all events fail if that flag is false.