473,607 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ 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 1408
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**********@g mail.comwrote in message
news:b6******** *************** ***********@i12 g2000prf.google groups.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
5983
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
28
12077
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
4216
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 "Search" for searching documents on that path. This search process runs in a separate thread so that I can search for multiple paths simultaneously. I face problem here. After starting the search for one path (that is starting one thread), when I...
5
27375
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 that catches an expected exception. The method in the DLL throws the exception back out. When in debug mode, the process just exits.
4
5502
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 a timeout less than the time required to process the code section it protects. The code listed below is just a small application I wrote to check the behavious of the different threading / synchronization techniques. Basically the application...
44
4203
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 user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box, etc.). 2. Low-level operations that are used to carry out the high level tasks
5
5733
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 thread.Abort()) is reported twice: once in the debug window, and once through the message box. Is it because the thread was sleeping when the exception occurred?
16
2533
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 method: // --- Create an Exception Handler for Thread Exceptions ---------------- Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException);
2
1615
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 exception handling here" )
7
4762
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 generating events to be processed and a "Proc" thread that processes incoming events from a queue. There will be additional threads as well that asynchronously insert events into the queue to be processed, but they are not a part of this so i...
0
8049
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8463
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...
1
8128
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8322
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6803
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...
0
5471
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
3953
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2461
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
1
1574
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.