472,374 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

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 1550
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jim O'Neil [Sybase] | last post by:
In designing a new control for general use, I have come across a design decision involving exceptions... I know that TargetSite returns the name of the method that threw the exception; however,...
3
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
2
by: | last post by:
I am looking for a easy way to trap an Exception that may occurr in any one of 30 child web controls to be trapped at the topmost parent WebUser control or Page Level. I have tried variations of...
19
by: Diego F. | last post by:
I think I'll never come across that error. It happens when running code from a DLL that tries to write to disk. I added permissions in the project folder, the wwwroot and in IIS to NETWORK_SERVICE...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
0
by: Gursharan | last post by:
Hi, I get this error after I did a load test on my website (500 constant user load in team system for 35 minutes). This error is logged after about 1 minute of load testing and is logged every...
0
by: Ben Crinion | last post by:
Hi Im having a bit of a problem with an exception that doesnt seem to be bubbling up from a user control to its containing user control. The exception can occur on an event fired by a user...
1
by: Efi Merdler | last post by:
Hi, I created a user control, but instead of handling exception in the user control level I prefer to handle them in the containing form. In the load event of the containing form I'm using:...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.