Abort a class in NEW() ?

  • Thread starter Thread starter Edwin Knoppert
  • Start date Start date
E

Edwin Knoppert

I'm using VB in ASP.NET, i would like to abort a class.
Best would be during the new member.
The result should be: Nothing

Is this possible?
 
What do you mean with 'aborting' a class?

If you mean setting an instance of a class to Nothing in the constructor of
that class... AFAIK that can't be done.
 
No. I'm almost positive new is always guaranteed to return an instance, or
throw an exception, no alternatives.

Karl
 
Oh, and by the way, it's a good thing that it can't be done, else you'd have
to check for null each time you used new...ugh..ugly code.

The solution, by the way, is to your a Factory. make the constructor
private, and then create a static (shared in vb.net) method:

public class product
private sub new
end sub

public shared function CreateInstance() as Product
if (whatever) then
return nothing
end if
return new Product()
end function
end class
 
Maybe you are right.

Similar:
A com interface should be possible to be recreated if it could be created
the first time.
(A short of guarantee/guideline which should be followed)
I guess it's no different for these kind of objects qua strategy.
 
Which trimester?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 
Huh?
Elaborate..


Kevin Spencer said:
Which trimester?

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 
Sorry, Edwin. It was an abortion joke. Tasteless, and probably meaningless
in Holland. Pay no attention to the man behind the curtain.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 

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

Back
Top