Could you please explain to me what the difference is between an error and an exception?
Exception: When a step in some action fails, all the subsequent steps in that action are simply NOT executed. This is where exceptions shine.
Error: is when, like in the first case you want to halt execution of the current code, but before you do you need to free any resources previously allocated.
Having that said,
Exception class has HResult property. HRESULT is a 32-bit value, divided into three different fields: a severity code, a facility code, and an error code.
Have a look at this post, will help you understand better