Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proper way to stop New() execution
Message
 
To
29/10/2006 20:23:40
General information
Forum:
ASP.NET
Category:
Class design
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01165405
Message ID:
01165650
Views:
13
>I have a class which contains a New() event. On the object, I also have a New() event which contains as the first line the MyBase() code to call the default New() event. However, in the New() event of the object, on a particular situation, I need to avoid the creation of the object. Basically, on a specific condition, I need to redirect to another page and stop the execution of the New() event. How can one accomplish this?

If you have code that needs to exit during construction you probably have a design flaw <s>...

Seriously you should break any 'exit capable' code out into a separate call that is made, like Init() or something to that effect.

If you really need to fail as part of the constructor the only way to kill the call chain is to throw an exception as Alexandre pointed out.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform