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

One strength of managed code lies in the structured approach to error handling using exceptions. Recall our native code fragment in the context of the goto statement’s discussion in Chapter 7, “Simple Control Flow,” in the section “The goto Statement?” Let’s refresh our minds and highlight a few aspects of it:

// Dealing with HRESULT return codes in C or C++.HRESULT InitDownloadManager(){    IBackgroundCopyManager* g_pbcm = NULL;    HRESULT hr;    hr = CoInitializeEx(NULL,                        COINIT_APARTMENTTHREADED);    if (FAILED(hr))        goto Exit;    hr = CoCreateInstance(__uuidof(BackgroundCopyManager), NULL,                          CLSCTX_LOCAL_SERVER,                          __uuidof(IBackgroundCopyManager), ...

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