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:

images

This approach of error checking is tedious and greatly disrupts the flow of the code, especially because we expect errors to happen only occasionally. Also, there’s little flexibility in the propagation of detailed error information; GetLastError values in Win32 and obscure HRESULT values in COM are hardly to be called descriptive. To propagate error codes to the place where the ...

Get C# 4.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.