473,320 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

MT Exception Handling

I currently have a multi-threaded server application with worker threads and
a core thread. For all of these threads I have something like the following
code:

uint32 __stdcall CCore::EntryPoint(void *pV)
{
CCore *pCore = (CCore *)pV;

try
{
while(true)
{
pCore->Update();
Sleep(20);
}
}
catch(...)
{
}

return 0;
}

Currently I don't do anything in the catch block. If I get an exception in
one of my threads it stops running, allowing other threads to continue. But
I would like to restart the thread. Would it be ok to put the try catch
blocks in a while block like the code below? Will this allow the thread to
continue, providing the original bug which caused the exception doesn't
reoccur? Obviously I should log the exception too so I can look into it,
but I would like my server to continue running if at all possible.

uint32 __stdcall CCore::EntryPoint(void *pV)
{
CCore *pCore = (CCore *)pV;

while(true)
{
try
{
while(true)
{
pCore->Update();
Sleep(20);
}
}
catch(...)
{
}
}

return 0;
}
Mar 29 '06 #1
4 1506
MadSage wrote:
Currently I don't do anything in the catch block. If I get an exception in
one of my threads it stops running, allowing other threads to continue. But
I would like to restart the thread. Would it be ok to put the try catch
blocks in a while block like the code below? Will this allow the thread to
continue, providing the original bug which caused the exception doesn't
reoccur? Obviously I should log the exception too so I can look into it,
but I would like my server to continue running if at all possible.


You should be sure to diferentiate a bug and an exception.
If you got an exception because something that you might have expected
to fail in extreme circunstances (memory allocation, io error), then it
is ok to retry it after fixing the problem, if it can be done.
If you got a bug there, then it is better to have it fail loudly so you
can look at it. In my view, this will prevent a lot of future headache.

Marco Costa
Mar 29 '06 #2

"Marco Costa" <co***@gamic.com> wrote in message
news:20************@legba.gamic.com...
MadSage wrote:
Currently I don't do anything in the catch block. If I get an exception in one of my threads it stops running, allowing other threads to continue. But I would like to restart the thread. Would it be ok to put the try catch
blocks in a while block like the code below? Will this allow the thread to continue, providing the original bug which caused the exception doesn't
reoccur? Obviously I should log the exception too so I can look into it, but I would like my server to continue running if at all possible.


You should be sure to diferentiate a bug and an exception.
If you got an exception because something that you might have expected
to fail in extreme circunstances (memory allocation, io error), then it
is ok to retry it after fixing the problem, if it can be done.
If you got a bug there, then it is better to have it fail loudly so you
can look at it. In my view, this will prevent a lot of future headache.

Marco Costa


Yes, this is why I said I should log the exception. At the moment I have a
bug which appears very rarely. Our game should go beta next week with 4000
beta testers. If this bug happens to appear, I would like the server to at
least attempt to recover from it, rather than stopping the whole beta test
for possibly several hours.
Mar 29 '06 #3
MadSage wrote:
I currently have a multi-threaded server application with worker threads and
a core thread. For all of these threads I have something like the following
code:

uint32 __stdcall CCore::EntryPoint(void *pV)
{
CCore *pCore = (CCore *)pV;

try
{
while(true)
{
pCore->Update();
Sleep(20);
}
}
catch(...)
{
}

return 0;
}

Currently I don't do anything in the catch block. If I get an exception in
one of my threads it stops running, allowing other threads to continue. But
I would like to restart the thread. Would it be ok to put the try catch
blocks in a while block like the code below? Will this allow the thread to
continue, providing the original bug which caused the exception doesn't
reoccur?
There's no inherent problem with having the try-catch in a loop, and
the multithreaded-ness of the program seems to be irrelevant as far as
your question is concerned. (In general, you shouldn't allow
execeptions to propogate outside your code to a caller you don't
control, such as when you utilize OS callbacks like it appears you are
doing here, and, likewise you should make sure each thread catches all
of its exceptions since otherwise they will propogate to OS-specific
threading code.) The real question is, "Is it safe to re-execute
CCore::Update() after an *unknown* exception is caught?"
Obviously I should log the exception too so I can look into it,
but I would like my server to continue running if at all possible.

[snip]

Right, but you'll have to catch a specific exception class (perhaps
using a reference to a base class like std::exception) to get any
information out of it. <OT>Also consider that Microsoft uses
"structured exception handling" to make certain errors (e.g., access
violations, stack overflows, etc.) look like exceptions. You can handle
these with a catch(...) or with their non-standard
__try/__except/__finally keywords. Check out your documentation for
more.</OT>

Cheers! --M

Mar 29 '06 #4

"mlimber" <ml*****@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
MadSage wrote:
I currently have a multi-threaded server application with worker threads and a core thread. For all of these threads I have something like the following code:

uint32 __stdcall CCore::EntryPoint(void *pV)
{
CCore *pCore = (CCore *)pV;

try
{
while(true)
{
pCore->Update();
Sleep(20);
}
}
catch(...)
{
}

return 0;
}

Currently I don't do anything in the catch block. If I get an exception in one of my threads it stops running, allowing other threads to continue. But I would like to restart the thread. Would it be ok to put the try catch
blocks in a while block like the code below? Will this allow the thread to continue, providing the original bug which caused the exception doesn't
reoccur?


There's no inherent problem with having the try-catch in a loop, and
the multithreaded-ness of the program seems to be irrelevant as far as
your question is concerned. (In general, you shouldn't allow
execeptions to propogate outside your code to a caller you don't
control, such as when you utilize OS callbacks like it appears you are
doing here, and, likewise you should make sure each thread catches all
of its exceptions since otherwise they will propogate to OS-specific
threading code.) The real question is, "Is it safe to re-execute
CCore::Update() after an *unknown* exception is caught?"
Obviously I should log the exception too so I can look into it,
but I would like my server to continue running if at all possible.

[snip]

Right, but you'll have to catch a specific exception class (perhaps
using a reference to a base class like std::exception) to get any
information out of it. <OT>Also consider that Microsoft uses
"structured exception handling" to make certain errors (e.g., access
violations, stack overflows, etc.) look like exceptions. You can handle
these with a catch(...) or with their non-standard
__try/__except/__finally keywords. Check out your documentation for
more.</OT>

Cheers! --M


Great, thanks.
Mar 29 '06 #5

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

Similar topics

11
by: adi | last post by:
Dear all, This is more like a theoretical or conceptual question: which is better, using exception or return code for a .NET component? I had created a COM object (using VB6), which uses...
6
by: Daniel Wilson | last post by:
I am having exception-handling and stability problems with .NET. I will have a block of managed code inside try...catch and will still get a generic ..NET exception box that will tell me which...
7
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
3
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech...
2
by: tom | last post by:
Hi, I am developing a WinForm application and I am looking for a guide on where to place Exception Handling. My application is designed into three tiers UI, Business Objects, and Data Access...
9
by: C# Learner | last post by:
Some time ago, I remember reading a discussion about the strengths and weaknesses of exception handling. One of the weaknesses that was put forward was that exception handling is inefficient (in...
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...
4
by: Ele | last post by:
When Exception handling disabled compiler still spits out "C++ exception handler used." Why is that? Why does it ask for "Specify /EHsc"? Thanks! c:\Program Files\Microsoft Visual Studio...
41
by: Zytan | last post by:
Ok something simple like int.Parse(string) can throw these exceptions: ArgumentNullException, FormatException, OverflowException I don't want my program to just crash on an exception, so I must...
1
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.