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), ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access