473,394 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Aborting a constructor

Folks,

I have a plug-in system where I have a host that creates child forms
to be displayed (in an MDI manner). One requirement is that if certain
conditions apply, a child form should not be created, e.g. I would
have to be able to abort the child's constructor, if I see that
certain things are missing.

How can I do this? I come from Delphi, and we used to have a "silent"
exception called "Abort" there - throw it in the constructor and the
execution of the constructor was stopped right there, and a null
pointer was returned (instead of a created instance) - is there
something similar in C# ? Can't seem to find anything to that
effect.....

Thanks!
Marc

================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Nov 15 '05 #1
2 2241
Marc Scheuner [MVP ADSI] <m.********@inova.SPAMBEGONE.ch> wrote:
I have a plug-in system where I have a host that creates child forms
to be displayed (in an MDI manner). One requirement is that if certain
conditions apply, a child form should not be created, e.g. I would
have to be able to abort the child's constructor, if I see that
certain things are missing.

How can I do this? I come from Delphi, and we used to have a "silent"
exception called "Abort" there - throw it in the constructor and the
execution of the constructor was stopped right there, and a null
pointer was returned (instead of a created instance) - is there
something similar in C# ? Can't seem to find anything to that
effect.....


The equivalent is to have a static method which calls a constructor and
either returns the new reference or null if an exception occurs. I for
one am very glad that constructors can't silently return null!

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2
Marc,
To further Jon's comment.

I would considering having the static method return a NullObject instead of
null. Depending on how far & wide the returned object was going to be used.
This avoids checking for null all over your code...

A NullObject is an application of the Special Case pattern.
http://www.martinfowler.com/eaaCatalog/specialCase.html

Hope this helps
Jay

"Marc Scheuner [MVP ADSI]" <m.********@inova.SPAMBEGONE.ch> wrote in message
news:km********************************@4ax.com...
Folks,

I have a plug-in system where I have a host that creates child forms
to be displayed (in an MDI manner). One requirement is that if certain
conditions apply, a child form should not be created, e.g. I would
have to be able to abort the child's constructor, if I see that
certain things are missing.

How can I do this? I come from Delphi, and we used to have a "silent"
exception called "Abort" there - throw it in the constructor and the
execution of the constructor was stopped right there, and a null
pointer was returned (instead of a created instance) - is there
something similar in C# ? Can't seem to find anything to that
effect.....

Thanks!
Marc

================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason | last post by:
I have a job created on my server which runs a stored procedure. The SP uses a cursor on a recordset to insert rows into a table (via a stored procedure - hence the cursor). It is expected that...
1
by: K0 | last post by:
Hi everyone I have a question: I have created a small windows service and runs ok. I have a problem, tho. I would like to abort uninstalling of the service if it is currently running, so I...
3
by: Patrick De Ridder | last post by:
Given: I call Form2 from Form1. I throw an exception in Form2. A MessageBox ("Fatal error") is shown with an OK button. Question 1: I want to abort everything after pressing the OK button....
1
by: johnny | last post by:
In a multi-threaded application, say a worker thread makes an asynchronous call and specifies a callback method. But before the callback is executed, the thread is aborted by its creator. What is...
2
by: Xarky | last post by:
Hi, I am writing a small program, that makes use of threads. Now in on of the threads I have a critical section, where I am using the Monitor to handle this. *** Thread_1 *** started for(...)...
3
by: Jeff Greenland | last post by:
Hello everyone, I am having problems with Timers in a web application. They just seem to stop running after 15 minutes or so. My web application is set up like this: When a user hits a...
7
by: archana | last post by:
Hi all, I am having application in which i am doing asynchronous call.I am using manualresetevent to wait for asynchronous call to complete. I want to stop asynchronous call after certain...
0
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I read from a serialport using a worker thread. Because the worker thread t does not loop often, I cannot wait to terminate the worker thread using a boolean in the While condition. So I have a...
2
by: cookspyder | last post by:
I have a simple socket client code that sends the contents of a syslog over to a server when it finds an error. It has been working fine in a while loop of read open socket send line and close...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.