473,804 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trapping exceptions encountered in user controls

Hi,

I have create a user control which has a dropdown. The user control
internaly handles the Selected_Index_ Changed event of the dropdown. If
there is an error/exception in handling it, I would like the
containing page to know of it. How can I make this possible? The
containing page does not know of the dropdown.

Thanks,
Yash
Jan 17 '08 #1
5 1484
To give you an idea therotically.
1. Declare event in your usercontrol.
2. From your page trap the event UserControl += new MyEvent( ...... )
3. OnException inside UserControl Raise the Event
4. You Page event handdler will receive the event and execute your function.

if you find difficult then i shall spend sometime to code and post it here.

Regards
JIGNESH

"Yash" wrote:
Hi,

I have create a user control which has a dropdown. The user control
internaly handles the Selected_Index_ Changed event of the dropdown. If
there is an error/exception in handling it, I would like the
containing page to know of it. How can I make this possible? The
containing page does not know of the dropdown.

Thanks,
Yash
Jan 17 '08 #2
It doesn't matter. The exception bubbles and will be handled at the parent
level inside the hosting application (make sure you don't hide the exception
in your user control ???)...
--
Patrice
"Yash" <ya****@gmail.c oma écrit dans le message de news:
eb************* *************** **...legroup s.com...
Hi,

I have create a user control which has a dropdown. The user control
internaly handles the Selected_Index_ Changed event of the dropdown. If
there is an error/exception in handling it, I would like the
containing page to know of it. How can I make this possible? The
containing page does not know of the dropdown.

Thanks,
Yash

Jan 17 '08 #3
But where will the try and catch be in the containg page to handle the
bubbled exception?

Raising an OnError event may work. But is there another way?
Jan 17 '08 #4
Either in the Page_Error event or in the global exception event handler (my
personal preference)...

The general idea is that exceptions are propagated automatically to callers.
So the first step could be to check your first assumption. This is not
because the dropdown is not an object known from the parent page that
exceptions thrown there are not propagated back to the caller (it just uses
the call stack to pass the exception to calling code).

With this in mind the general principle would be to have a global error
handler at the highest possible level so that you knows that something goes
wrong and that you can fix the coding error. Then you can place a local
exception handler at choosen places :
- either because your code or the user could do something to solve the
particular exception you are trapping at this place (and in this case you
don't let this particular one to propagate higher)
- or to do some cleanup on unmanaged resources (but in this case you still
let the exception goes higher as once resources are released you still want
to know that your application has en error you should fix).

You should find more details areound :
http://msdn2.microsoft.com/en-us/library/6kzk0czb.aspx

--
Patrice

"Yash" <ya****@gmail.c oma écrit dans le message de news:
3b************* *************** **...legroup s.com...
But where will the try and catch be in the containg page to handle the
bubbled exception?

Raising an OnError event may work. But is there another way?

Jan 17 '08 #5

Thanks
Jan 18 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1940
by: pythos | last post by:
I have a piece of code like this: try: some code except: print >> sys.stderr, "error: ", sys.exc_info() When an exception is thrown from the code, what I see on the console is this:
33
3035
by: Steven Bethard | last post by:
I feel like this has probably been answered before, but I couldn't find something quite like it in the archives. Feel free to point me somewhere if you know where this has already been answered. I have a list in a particular order that I want to split into two lists: the list of every nth item, and the list of remaining items. It's important to maintain the original order in both lists. So the first list is simple:
4
1741
by: Aaron W. LaFramboise | last post by:
I'm seeking a solution to my C++-life long dilemma of how to deal with errors when exceptions aren't appropriate. Below I highlight two error cases, which mainly occur when trying to handle "unexpected" errors on system interfaces. I am an experienced modern C++ programmer, and I'm mainly interested in the case where the error is in a generic, reusable component where invasive control over the user is unacceptable. Case 1: An error...
6
4765
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
3
6904
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records from rsSource into rsDest - if it finds a key violation then it deletes the current record from rsDest and adds the new record from rsSource. This works perfectly - but only for the first found duplicate record, it brings up the error
19
2202
by: KKramsch | last post by:
One of the features from other languages that I miss most in C is trappable exceptions. More specifically, I think it's great to be able to demarcate a whole block of code where several exceptions can happen at various points, so that any one of these exceptions can be trapped and handled by the exception-handling code collected in one place after the block. This also means that the exception generating code can be much cleaner, since...
3
5879
by: =B= | last post by:
Hi all, I was wondering if anyone has had any luck with trapping the <BODY> onUnload() event in ASP.NET? The thing is, I'm writing code for an Intranet site. The code makes a call to a third-party component (think of it as a lock) when the page loads. Now the OK and Cancel server buttons I can handle and use to release the lock as required. But previously in classic ASP I had been trapping the user hitting the close 'x' button by...
4
277
by: Mike | last post by:
I have a C# aspx page that calls a C# class file for db access, data, etc. If one of the "functions" I call in the class has an error how can i pass that error back to the aspx page and then display it?
4
2101
by: Bill | last post by:
Despite our best efforts occasionally in an aspx file, something like <%=x%> where x is not defined sqeaks by and I get the ugly asp error message. I want to be able to identify this particular error and issue a pretty message. I use the global.asax on application error to handle generalized error handling. I want to be able to capture and identify the above error.
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9175
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.