O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exception Handling

Error handling is a tricky business. Disciplined error code checking on function return has plagued developers for many years. For example, the following fragment is an excerpt from the Platform SDK documentation on a COM-based API for file transfer:

IBackgroundCopyManager* g_pbcm = NULL;HRESULT hr;// Specify the appropriate COM threading model for your application.hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);if (SUCCEEDED(hr)){    hr = CoCreateInstance(__uuidof(BackgroundCopyManager), NULL,                          CLSCTX_LOCAL_SERVER,                          __uuidof(IBackgroundCopyManager),                          (void**) &g_pbcm);    if (SUCCEEDED(hr))    {        // Use g_pbcm to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required