Since I can't use Microsoft as an example for best practice since their exception messages are stored in resource files out of necessity, I am forced to ask where should exception messages be stored.
I figure it's probably one of common locations I thought of
The exception site list is managed in the Security tab of the Java Control Panel. The list is shown in the tab.
The content of the exception message dependents on the receiver of the message - so you have to put yourself in that person's shoes. A support engineer will need to be able to identify the source of the error as quickly as possible. Include a short descriptive string plus any data that can help troubleshoot the issue.
Use grammatically correct error messages Write clear sentences and include ending punctuation. Each sentence in the string assigned to the Exception. Message property should end in a period.
An exception occurs when a package or shipment encounters an unforeseen event, which could result in a change to the expected delivery day. Examples of exception include: address unknown, damage to shipment, or signature not received.
If your exceptions are strongly typed, you don't need to worry about messages. Messages are for presenting errors to users, and exceptions are for controlling flow in exceptional cases.
throw new InvalidOperationException("The Nacho Ordering system is not responding.");
could become
throw new SystemNotRespondingException("Nacho Ordering");
In the latter case, there's nothing to translate, and therefore no need to worry about localization.
I may get shot (well, downvoted) for this, but why not "where you create the exception"?
throw new InvalidDataException("A wurble can't follow a flurble");
Unless you're going to internationalize the exception messages (which I suggest you don't) do you particularly need them to be constants etc? Where's the benefit?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With