469,568 Members | 1,498 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

Exception in the User Control

Hi All,

I have a requirement. I am throwing an exception from the Page_Load of my
user control I want
to catch this in my container page. Is this possible?
The Page_Load of user control is executed after the Page_Load of the page.
So we cannot catch this in the Page_Load of the page. So my question where
in the page i will catch the exception thrown form the user control.

I don't want any event to be raised from the user control.

PLEASE HELP ME.

Thanks

Prince
Nov 19 '05 #1
4 1502
You can have an error handler at the Page level (Page_Error) which catches
the error and does some processing, but it might have other effects
(unwanted ones) on your app. But try it out.

Personally if it is known that error is raised I would either:

-Try to handle it in the UC itself (own error handler there) and not let
Page do anything with it

or

-if Page needs know about it but doesn't need to do more, indeed raise an
event from the UC

And please note that raising exceptions shouldn't be normal logic, but they
would really need to be used in exceptional situations. Maybe you could
redesign it so that Page invokes the action in UC by calling UC's method,
when it could also handle possible exceptions or return data coming from the
method call (which would indicate error case)

But all these depends on what you need to do withing the Page 8there could
be other alternatives as well). Write the error data for user or something?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
"Prince Mathew" <pr****************@hotmail.com> wrote in message
news:OT**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I have a requirement. I am throwing an exception from the Page_Load of my
user control I want
to catch this in my container page. Is this possible?
The Page_Load of user control is executed after the Page_Load of the page.
So we cannot catch this in the Page_Load of the page. So my question where
in the page i will catch the exception thrown form the user control.

I don't want any event to be raised from the user control.

PLEASE HELP ME.

Thanks

Prince

Nov 19 '05 #2
Hi,

"Write the error data for user or something?" Thats what i want. But with
out handling the error event or raising an event from the UC can i catch
that exception from the container Page.

Thanks
Prince

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl...
You can have an error handler at the Page level (Page_Error) which catches
the error and does some processing, but it might have other effects
(unwanted ones) on your app. But try it out.

Personally if it is known that error is raised I would either:

-Try to handle it in the UC itself (own error handler there) and not let
Page do anything with it

or

-if Page needs know about it but doesn't need to do more, indeed raise an
event from the UC

And please note that raising exceptions shouldn't be normal logic, but
they would really need to be used in exceptional situations. Maybe you
could redesign it so that Page invokes the action in UC by calling UC's
method, when it could also handle possible exceptions or return data
coming from the method call (which would indicate error case)

But all these depends on what you need to do withing the Page 8there could
be other alternatives as well). Write the error data for user or
something?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
"Prince Mathew" <pr****************@hotmail.com> wrote in message
news:OT**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I have a requirement. I am throwing an exception from the Page_Load of my
user control I want
to catch this in my container page. Is this possible?
The Page_Load of user control is executed after the Page_Load of the
page. So we cannot catch this in the Page_Load of the page. So my
question where in the page i will catch the exception thrown form the
user control.

I don't want any event to be raised from the user control.

PLEASE HELP ME.

Thanks

Prince


Nov 19 '05 #3
> But with out handling the error event or raising an event from the UC can
i catch that exception from the container Page.
Nope, because there isn't anything in "middle" that would initiate that
logic from page, or where you could plug your own code (as long as you keep
it withing Load event of the UC). As I said, it would mean a change so that
Page is the responsible for initiating the action (calling the method in UC
which can cause the error) if you want to have try...catch block to handle
it

Exception in Page_Error comes as general Exception type. If you'd want it
typed, you'd need to check the type first and cast to it (if there's chance
for expections of multiple type). Page_Error runs for all unhandled
exceptions.

Maybe you could get around it by assigning the Label or what the error msg
should be written to, as a proprrty from page to the UC, so UC could set it
itself. Or its ID. Anyways, its your call. The responibility goes into two
possible ways here, either Page does the writing or then UC does it. If Page
does it, it needs to get to the exception somehow and these are the means.

-
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

..

"Prince Mathew" <pr****************@hotmail.com> wrote in message
news:Oj**************@tk2msftngp13.phx.gbl... Hi,

"Write the error data for user or something?" Thats what i want. But with
out handling the error event or raising an event from the UC can i catch
that exception from the container Page.

Thanks
Prince

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl...
You can have an error handler at the Page level (Page_Error) which
catches the error and does some processing, but it might have other
effects (unwanted ones) on your app. But try it out.

Personally if it is known that error is raised I would either:

-Try to handle it in the UC itself (own error handler there) and not let
Page do anything with it

or

-if Page needs know about it but doesn't need to do more, indeed raise an
event from the UC

And please note that raising exceptions shouldn't be normal logic, but
they would really need to be used in exceptional situations. Maybe you
could redesign it so that Page invokes the action in UC by calling UC's
method, when it could also handle possible exceptions or return data
coming from the method call (which would indicate error case)

But all these depends on what you need to do withing the Page 8there
could be other alternatives as well). Write the error data for user or
something?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
"Prince Mathew" <pr****************@hotmail.com> wrote in message
news:OT**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I have a requirement. I am throwing an exception from the Page_Load of
my user control I want
to catch this in my container page. Is this possible?
The Page_Load of user control is executed after the Page_Load of the
page. So we cannot catch this in the Page_Load of the page. So my
question where in the page i will catch the exception thrown form the
user control.

I don't want any event to be raised from the user control.

PLEASE HELP ME.

Thanks

Prince



Nov 19 '05 #4
Thanks
Teemu

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:eT**************@TK2MSFTNGP14.phx.gbl...
But with out handling the error event or raising an event from the UC can
i catch that exception from the container Page.


Nope, because there isn't anything in "middle" that would initiate that
logic from page, or where you could plug your own code (as long as you
keep it withing Load event of the UC). As I said, it would mean a change
so that Page is the responsible for initiating the action (calling the
method in UC which can cause the error) if you want to have try...catch
block to handle it

Exception in Page_Error comes as general Exception type. If you'd want it
typed, you'd need to check the type first and cast to it (if there's
chance for expections of multiple type). Page_Error runs for all unhandled
exceptions.

Maybe you could get around it by assigning the Label or what the error msg
should be written to, as a proprrty from page to the UC, so UC could set
it itself. Or its ID. Anyways, its your call. The responibility goes into
two possible ways here, either Page does the writing or then UC does it.
If Page does it, it needs to get to the exception somehow and these are
the means.

-
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

.

"Prince Mathew" <pr****************@hotmail.com> wrote in message
news:Oj**************@tk2msftngp13.phx.gbl...
Hi,

"Write the error data for user or something?" Thats what i want. But with
out handling the error event or raising an event from the UC can i catch
that exception from the container Page.

Thanks
Prince

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl...
You can have an error handler at the Page level (Page_Error) which
catches the error and does some processing, but it might have other
effects (unwanted ones) on your app. But try it out.

Personally if it is known that error is raised I would either:

-Try to handle it in the UC itself (own error handler there) and not let
Page do anything with it

or

-if Page needs know about it but doesn't need to do more, indeed raise
an event from the UC

And please note that raising exceptions shouldn't be normal logic, but
they would really need to be used in exceptional situations. Maybe you
could redesign it so that Page invokes the action in UC by calling UC's
method, when it could also handle possible exceptions or return data
coming from the method call (which would indicate error case)

But all these depends on what you need to do withing the Page 8there
could be other alternatives as well). Write the error data for user or
something?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
"Prince Mathew" <pr****************@hotmail.com> wrote in message
news:OT**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I have a requirement. I am throwing an exception from the Page_Load of
my user control I want
to catch this in my container page. Is this possible?
The Page_Load of user control is executed after the Page_Load of the
page. So we cannot catch this in the Page_Load of the page. So my
question where in the page i will catch the exception thrown form the
user control.

I don't want any event to be raised from the user control.

PLEASE HELP ME.

Thanks

Prince



Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jim O'Neil [Sybase] | last post: by
3 posts views Thread by Professor Frink | last post: by
44 posts views Thread by craig | last post: by
19 posts views Thread by Diego F. | last post: by
reply views Thread by Gursharan | last post: by
reply views Thread by Ben Crinion | last post: by
1 post views Thread by Efi Merdler | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.