0
Reply

How to catch a Custom Control's exception within my form?!

Ask a question
bijan

bijan

15y
2.2k
1
Hi ppl
My question might seem a little bit newbie, which is why I called a newbie in this area ;)
See, I wrote a custom control, which holds couple of textboxes, I  want an error message to be shown if the submit button is pressed but some of the textboxes are empty. I wrote a throw exception for it and I wanted to show it via an errorProvider component, which I found is impossible to implement within a Custom Control, it should only be used within a form!
So, I just decided to catch that exception that the custom control throws, in the form that actually implements it. But to my dispair, I don't know where to write my try, catch block.
I tried enclosing InitializeCompoent() in it:

[code]
            try
            {
                InitializeComponent();
            }
            catch (NullEntryException ex)
            {
                MessageBox.Show("damn");
            }
[/code]
but it doesn't work. I also tried to put the line that actually instantiates my custom control inside it:
[code]
            try
            {
                this.addClientUserControl1 = new Presentation.Clients.addClientUserControl();
            }
            catch (NullEntryException ex)
            {
            }
[/code]

but it doesn't work either! What can I do?