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 ...
Get C# 5.0 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.