This is a mirror of official site: http://jasper-net.blogspot.com/

How to turn off the exception handler that COM "helpfully" wraps around your server

| Sunday, January 23, 2011
Historically, COM placed a giant try/except around your server's methods. If your server encountered what would normally be an unhandled exception, the giant try/except would catch it and turn it into the error RPC_E_SERVERFAULT. It then marked the exception as handled, so that the server remained running, thereby "improving robustness by keeping the server running even when it encountered a problem."

Mind you, this was actually a disservice.

The fact that an unhandled exception occurred means that the server was in an unexpected state. By catching the exception and saying, "Don't worry, it's all good," you end up leaving a corrupted server running. For example:

HRESULT CServer::DoOneWork(...)
{
CWork *pwork = m_listWorkPending.RemoveFirst();
if (pwork) {
  pwork->UpdateTimeStamp();
  pwork->FrobTheWidget();
  pwork->ReversePolarity();
  pwork->UnfrobTheWidget();
  m_listWorkDone.Add(pwork);
}
return S_OK;
}

Suppose there's a bug somewhere that causes pwork->Reverse­Polarity() to crash. Maybe the problem is that the neutrons aren't flowing, so there's no polarity to reverse. Maybe the polarizer is not property initialized. Whatever, doesn't matter what the problem is, just assume there's a bug that prevents it from working.

Read more: The old new thing

Posted via email from Jasper-net

0 comments: