MT Exception Handling



 DEVELOP > c-Plus-Plus > MT Exception Handling

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "MadSage"
Date: 29 Mar 2006 07:33:45 AM
Object: 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;
}
.

User: "Marco Costa"

Title: Re: MT Exception Handling 29 Mar 2006 08:25:37 AM
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
.
User: "MadSage"

Title: Re: MT Exception Handling 29 Mar 2006 10:09:42 AM
"Marco Costa" <costa@gamic.com> wrote in message
news:20iqf3-r2g.ln1@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.
.


User: "mlimber"

Title: Re: MT Exception Handling 29 Mar 2006 11:49:11 AM
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
.
User: "MadSage"

Title: Re: MT Exception Handling 29 Mar 2006 03:44:40 PM
"mlimber" <mlimber@gmail.com> wrote in message
news:1143654551.434230.253330@i40g2000cwc.googlegroups.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.
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER