Could you please explain to me what the difference is between an error and an exception?
An exception is an object of a type deriving from the System.Exception
class. It is used in a throw
statement to transfer control to a catch
clause in a try
block somewhere further up the call stack.
An error is just some code or message that you're meant to interpret. The problem with error codes is that you can decide to ignore them:
MethodThatReturnsAnError();
SomeCodeThatShouldNotExecuteOnError();
That call will simply ignore the error code if one is returned. However:
MethodThatThrowsAnException();
SomeCodeThatShouldNotExecuteOnError();
This cannot be ignored, and will transfer control up the stack, past "SomeCodeThatShouldNotExecuteOnError();
".