views:

238

answers:

5

I've seen both exception messages with and without a period. And I can think of some reasons of why both could be good.

  • No dot would give you the freedom to add the period or leave it out if you wanted to. Could be useful if the message was going in some sort of a titlebar or something.
  • WIth a dot you would always know that you had a "complete sentence" and it looks more finished.

Which one do you recommend?

Could also be an issue in localized resource strings. Obviously there you can't put a period after everything (Would look weird with periods after text on buttons and menu items etc.). But should you then leave the period out from everything to be consistent and add it later where useful? Or would you rather put a period where it seems fit? For example after all resource strings and exception messages that are sentences, but not after those that are words. But then, how about very short sentences? Like "Create a new file" for example. Could maybe leave out periods for strings that were considered actions as well... (Just thinking while im typing here...

Not the most important thing in the world, I know. But small things like this that tend to bug me after a while. I like consistency and to know why I do what I do. Problem is I'm not sure which one to go for :p

+7  A: 

Yes I usually treat the exception messages as full sentences, ending them with a period.

However, the message in the exception is meant for the developer, and not the end user. It may very well be that the same underlying exception should result in two different messages for the end user, depending on the context in which the exception-throwing method was called.

You really should show less technical, more user friendly messages to the user.

Fredrik Mörk
+1 for consistency with the .NET framework.
SealedSun
+3  A: 

i always use periods in my exception descriptions the simple fact is that sentences which are properly punctuated are easier to read and more professional looking which is important for percieved quality dont you think

Dave Markle
Interesting illustration.
Matthew Scharley
I think not showing exception messages to your end users would make perceived quality even higher.
Anders Sandvig
Yes, a correctly punctuated sentence with corect speling relay dose lokk moore proesionall
Guffa
@Anders -- depends on how you show it. If it's caught and presented correctly to the user, exceptions can be quite professional looking. Uncaught? Well, that's just a crash!
Dave Markle
+3  A: 

Exception messages in the framework are dot-terminated; I tend to do the same for that reason.
In any case, choose a style and try to stick to that...

Paolo Tedesco
A: 

Use your best judgement. I sometimes use exclamation mark as well. :-)

chikak
+1  A: 

Exception messages form a part of the developer interface to your application. Interfaces are generally designed with a view to helping the user perform some specific task, in the case of an exception, the interface provided should be designed to convey information about an error which has occured within the application.

When you decide to throw an exception and write a line like this:

throw new ArgumentException("The string must contain at least one character.");

then you have already made a number of decisions about the interface including:

  • Exception type
  • Lack of localised exception messages (use of hardcoded string usually implies this)
  • This exception is not the result of any other condition (no inner exception)

Remember, the developer interface exists to serve developes and the user interface to serve the user, the former has vastly different requirements than the latter so what is good for one might not be good for the other so a period in the exception message should not concern the user interface because it should not be visible to the end user

The use of a period is not a major decision in most cases but you should consider whether it's presence (or lack thereof) is beneficial or detrimental to the interface by considering points already raised invluding framework consistancy and localisation.

I know this post is a little wordy and possibly a little astronaught but I hope it is helpful to you

Crippledsmurf