Throwing Exception in a composite control

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Throwing Exception in a composite control

    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.
    KJ Guest

  2. Similar Questions and Discussions

    1. PDDOCSAVE -throwing unhandled exception
      Hi Everybody, When i am using PDDOCSAVE in my application to secure a file using Acrobat 9.0 in VC++ i am getting unhandled exception The code...
    2. #32101 [Com]: Exception in unknown on line 0 when throwing exception inside exception handler
      ID: 32101 Comment by: dhopkins at DonHopkins dot com Reported By: ceefour at gauldong dot net Status: No...
    3. #40033 [NEW]: Server Crashes when Throwing an Exception
      From: francisco dot a dot castillo at ge dot com Operating system: Linux Fedora Core 6 PHP version: 5.2.0 PHP Bug Type: ...
    4. #40033 [Opn->Fbk]: Server Crashes when Throwing an Exception
      ID: 40033 Updated by: iliaa@php.net Reported By: francisco dot a dot castillo at ge dot com -Status: Open...
    5. Possible to create a composite control that has a child control that is a validator that validates the composite control itself?
      I am attempting to create a composite control which has a label, followed by an optional error message, followed by two text boxes. I have...
  3. #2

    Default Re: Throwing Exception in a composite control

    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
    [email]john.saunders@surfcontrol.com[/email]


    "KJ" <klj_mcsd@hotmail.com> wrote in message
    news:d83a9214.0307231343.6a4ae279@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.

    John Saunders Guest

  4. #3

    Default Re: Throwing Exception in a composite control

    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
    [email]john.saunders@surfcontrol.com[/email]


    "Kyle Johnson" <klj_mcsd@hotmail.com> wrote in message
    news:%23TnJLTXUDHA.2460@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 [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    John Saunders Guest

  5. #4

    Default Re: Throwing Exception in a composite control

    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
    [email]john.saunders@surfcontrol.com[/email]



    "Kyle Johnson" <klj_mcsd@hotmail.com> wrote in message
    news:eWy6tMeUDHA.2004@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 [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    John Saunders Guest

  6. #5

    Default Re: Throwing Exception in a composite control

    Can you explain what you mean by 'error events'? I'm fairly new to this.
    Thanks for your help.


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Kyle Johnson Guest

  7. #6

    Default Re: Throwing Exception in a composite control

    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
    [email]john.saunders@surfcontrol.com[/email]

    "Kyle Johnson" <klj_mcsd@hotmail.com> wrote in message
    news:%232DrYZkUDHA.1396@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 [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    John Saunders Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139