best practice to handle error in multilingual application
i am developing a multilingual application in w开发者_JAVA百科hich i have to consider different errors..
suggest me whether i use error code or exceptions...
MS SharePoint throws exceptions like this:
....
Throw New SPException(SPResource.GetString("CannotChangeRootwebPerm", New Object() { Me.Url }))
....
which sounds reasonable. - you have an utility function which knows how to find the required message for current locale; you give each exception string a readable & logical name.
I'd always prefer Exceptions instead of arbitrary return values. A way to create multilinguar exceptions is to create a base class which takes care of translation, i.e.:
class TranslatedException : Exception {
private string translationKey = "base_exception";
public string ToString() {
return YourTranslationClass.GetTranslation(this.translationKey);
}
}
Other exceptions just need to inherit from this class and change the translationKey accordingly.
Use exceptions. Get localized error messages from a resource file or similar. Read this:
- Error codes or Exceptions? Why is Reliable Software so Hard?
精彩评论