473,480 Members | 3,098 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Exception in thread

PGP
Hello,

I have a library which does some database operations. There are threads in
the library which are transparent to the user. Database operations are done
in threads as they could be lengthy. When an exception occurs in a library
thread, i want to make this exception available to the user (user is usually
in the app's main thread). What is the common practice in such a scenario?

TIA
Priyesh
Nov 27 '07 #1
2 1405
On Nov 27, 9:26 am, "PGP" <priyesh_do_not_replywrote:
Hello,

I have a library which does some database operations. There are threads in
the library which are transparent to the user. Database operations are done
in threads as they could be lengthy. When an exception occurs in a library
thread, i want to make this exception available to the user (user is usually
in the app's main thread). What is the common practice in such a scenario?

TIA
Priyesh
Remember that threads share memory. They simply have their own
instruction pointer and stack. If you have one thread raise a
MessageBox, it will show up. If you modify a GUI, it will modify the
UI, not a copy of the UI. You simply have to ensure you have
concurrency. The common problem is that the thread starts at a point
such that it doesn't have any access to the interface. Well, you can
have the thread start in a method that is still at the interface
level, then wrap the non-interface code in a try/catch.

void threaded() // this is the entry-point of your thread
{
try
{
// start DB code
}
catch
{
// do UI concurrency to handle error.
}
}

You do most UI concurrency using BeginInvoke and EndInvoke. You should
be able to get what you want from what I have said.
Nov 28 '07 #2
PGP

<je**********@gmail.comwrote in message
news:b6**********************************@i12g2000 prf.googlegroups.com...
>
Remember that threads share memory. They simply have their own
instruction pointer and stack. If you have one thread raise a
MessageBox, it will show up. If you modify a GUI, it will modify the
UI, not a copy of the UI. You simply have to ensure you have
concurrency. The common problem is that the thread starts at a point
such that it doesn't have any access to the interface. Well, you can
have the thread start in a method that is still at the interface
level, then wrap the non-interface code in a try/catch.

void threaded() // this is the entry-point of your thread
{
try
{
// start DB code
}
catch
{
// do UI concurrency to handle error.
}
}

You do most UI concurrency using BeginInvoke and EndInvoke. You should
be able to get what you want from what I have said.
I do have a need to pass the Exception object back to the user. This i do
right now
by raising an event from catch handler with the exception in the event args.
This seems to work
correctly. One of my initial doubts was that if it would have lifetime
issues with the
exception object as it was created in another thread. Any information on why
this works
correctly will be helpful.
Nov 29 '07 #3

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

Similar topics

7
5959
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
28
12041
by: dcrespo | last post by:
Hi all, How can I get a raised exception from other thread that is in an imported module? For example: --------------- programA.py ---------------
4
4205
by: Bhavya Shah | last post by:
Hello, I am facing a very strange problem in my application. I have a form on which I select a path. I open the FolderBrowserDialog for path selection. Once the path is selected I press a button...
5
27364
by: David | last post by:
I am having a bit of a problem with catching an exception within a thread. Here is the scenario: I have a Windows Form. I create a new thread. This new thread calls a method in another DLL...
4
5485
by: Anders Borum | last post by:
Hello! I am working on improving my threading skills and came across a question. When working with the ReaderWriterLock class, I am getting an unhandled exception if I acquire a WriterLock with...
44
4155
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...
5
5720
by: Lucvdv | last post by:
Can someone explain why this code pops up a messagebox saying the ThreadAbortException wasn't handled? The first exception is reported only in the debug pane, as expected. The second (caused by...
16
2515
by: Chuck Cobb | last post by:
I'm implementing a centralized exception handling routine using the Enterprise Library Exception Management Application Block. I trap all unhandled exceptions to one place using the following...
2
1603
by: Robinson | last post by:
Hi, I have 2 menu items on the Debug menu of my application: Throw Exception On Form and Throw Exception In Worker Thread The former just executes: throw new Exception ( "I'm testing...
7
4744
by: Brendon Costa | last post by:
Hi all, I have a small python project i am working on. Basically i always have two threads. A "Read" thread that sits in a loop reading a line at a time from some input (Usually stdin) and then...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7061
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,...
1
6763
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5367
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,...
0
4503
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...
0
3015
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
574
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
210
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.