Should Exceptions Carry Error Code Information

Recently somebody asked me to clarify one of the exception guidelines. They were asking whether it's ok to have a property on exception types that provides access to an error code. I added the following annotation to one of the guidelines:

Do not return error codes. Exceptions are the primary means of reporting errors in frameworks. The chapter overview section describes the benefits of exceptions in detail.

Annotation (Krzysztof Cwalina): It’s ok for exceptions to have a property returning some kind of error code, but I would be very careful about this also. Each exception should carry two main pieces of information: the exception message explaining to the developer what went wrong and how to fix it and the exception type that should be used by handlers to decide what programmatic action to take. If you think you need to have a property on your exception that would return additional error code, think who this code is for. Is it for the developer or for the exception handler? If for the developer, add additional information to the message. If for the handlers, add a new exception type.