What does a good exception message look like?

Today I have to bring up a great article that is over a year old. They topic is what exception messages really should look like. As bonus I would like to increase the scope of the discussion to also include log messages and test failures.

The short version of the article is that exception messages are not for end users (for several reasons) but are for other developers. As such it should provide as much useful information as possible to the developer. In my opinion it is wrong to expect another developer to debug an exception in order to understand why it was thrown. As pointed out in the article, if the exception is a kind of UnknownSomethingException then the message should tell me what that value was. And that is just a simple example.

Now think a little further. Doesn't the same apply for log messages? I think so. And the what about failure messages from tests? In my opinion test failures fall in the same category - I should not need to run the test and debug it to understand why it failed.

No comments:

Post a Comment