By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,670 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,670 IT Pros & Developers. It's quick & easy.

Throwing Exception in a composite control

P: n/a
KJ
This is kind of hard to explain but I have a [composite control] The
controls are created with CreateChildControls(). Now let say I click a
button and an error occurs in the control. If I throw it up it goes
back to the web form. where do I catch the exception at?
Example
Webform

Composite Control

but_click

Throw e as exception

Then the exception goes back up the chain until it gets to the
webform. Can I catch the exception in any event on the webform?
Because after it get pass the control the chain is broken.

Or do I have to pass it as a parameter like RaiseEvent Click(Me, e,
exception)?

I hope this is clear. If anyone know of a good resource for throwing
exception from composite controls let me know.
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Does your control know how to handle the exception? Then it should catch the
exception in the catch block of a try-catch statement. The exception should
be caught where it can be handled.

If your control doesn't know what to do with the exception, then leave it
alone. It's up to the person who knows how to handle the exception to have
the exception handler.

BTW, this has nothing at all to do with composite controls. This is a basic
matter of one method calling another,. which calls another - which raises an
exception. Exception processing does nothing special with the control
hierarchy.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
"KJ" <kl******@hotmail.com> wrote in message
news:d8**************************@posting.google.c om...
This is kind of hard to explain but I have a [composite control] The
controls are created with CreateChildControls(). Now let say I click a
button and an error occurs in the control. If I throw it up it goes
back to the web form. where do I catch the exception at?
Example
Webform

Composite Control

but_click

Throw e as exception

Then the exception goes back up the chain until it gets to the
webform. Can I catch the exception in any event on the webform?
Because after it get pass the control the chain is broken.

Or do I have to pass it as a parameter like RaiseEvent Click(Me, e,
exception)?

I hope this is clear. If anyone know of a good resource for throwing
exception from composite controls let me know.

Nov 17 '05 #2

P: n/a
Why do you think you want to catch it in the webform? What do you expect to
do about such an exception? Are you concerned about some one particular
exception, or just exceptions in general?

Is your control explicitly throwing a particular exception? If so, then
please stop doing that. Exceptions are for exceptional circumstances.
They're not a general non-local goto.

You say it's not that easy with composite controls. You're dead wrong. Your
situation is in no way specific to controls, much less to composite
controls. This is nothing more than a chain of subroutine calls. I strongly
recommend that you stop asking your questions about controls and instead
just ask them about subroutines calling subroutines which call subroutines.

Has this exception ever occurred? In that case, one really big hint will be
the stack trace. Look at the trace and pretend you've never even _heard_
about controls!

If necessary, post the stack trace and I'll become less general. But I'm
concerned that if I do that, you won't learn the real lesson - that this has
nothing whatsoever to do with controls.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
"Kyle Johnson" <kl******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...


my problem is. Where do I catch the exception in the webform? If the was
a user control made of of html controls it would be simple but it's not
that easy with composite controls. I want to catch it at the webform
level

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #3

P: n/a
Kyle,

First, like I said, you should abstract the problem away from "controls" and
"web forms" to "components" and "component consumers".

However, you were given a good suggestion, one which would work whether this
were a "control" issue or a "component" issue. Your control should define an
Error event with the exception as a parameter. btnSearchClick (NOT "Search")
should catch any exceptions and should raise them as Error events to whoever
cares about Error events. Possibly even your Web Form.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

"Kyle Johnson" <kl******@hotmail.com> wrote in message
news:eW**************@TK2MSFTNGP10.phx.gbl...


Thank you for your help. I will post my stack trace. That might explain
my situation better. I'm not at work today so it will be tomorrow. Thank
you again
But just to let you know someone told me to pass the exception back as a
parameter in the event that gets raised to the webform. That does not
sound like the best way to do it.

Another example

Control

AddHandler btnSearch.Click AddressOf btnSearchClick

Sub btnSearchClick()
onclick()
End Sub
..... Sub OnClick()

Search()

End Sub
Sub Search()
Try
.
.
.
Catch
.
.
.
Throw New Exception(e.Message)

End Sub
When I click thesearch button on the control and If an exception occurs
in Search() and I need to get it to the webform that the control is in,
so a custom error object can handle it. How do I get it there?

Thanks again

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #4

P: n/a
Can you explain what you mean by 'error events'? I'm fairly new to this.
Thanks for your help.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #5

P: n/a
I meant an event called "Error" which is raised to indicate that an error
has occurred. Such an event can be handled by any number of pieces of code
which care whether an error has occurred.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

"Kyle Johnson" <kl******@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Can you explain what you mean by 'error events'? I'm fairly new to this.
Thanks for your help.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.