Exception firing at design time - how to avoid?

J

Jack Addington

1) I have created a visual control that relies on a logic class to do much
of its work.
2) The logic class will be assigned on the form through a register method.
3) I have a public property for accessing the control defined.
4) To avoid other people calling the control before it is initialized I
throw an ArgumentNullException in the propert.get section.

My problem is that when I place this visual control on a form, the exception
is firing. How do I get this exception to only fire at runtime or do I need
to re-arrange my code/thinking?

public LogicObj Logic
{
get
{
if ( _logic == null ) throw new ArgumentNullException(...);
return _logic;
}
}

thx

jack
 
J

John Vottero

Jack Addington said:
1) I have created a visual control that relies on a logic class to do much
of its work.
2) The logic class will be assigned on the form through a register method.
3) I have a public property for accessing the control defined.
4) To avoid other people calling the control before it is initialized I
throw an ArgumentNullException in the propert.get section.

My problem is that when I place this visual control on a form, the
exception is firing. How do I get this exception to only fire at runtime
or do I need to re-arrange my code/thinking?

Look at the DesignMode property. It's true when you're in a designer.

if (!DesignMode)...
 

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

Top