hi. i am developing a multilingual application in which i have to consider different errors..
suggest me whether i use error code or exceptions...
hi. i am developing a multilingual application in which i have to consider different errors..
suggest me whether i use error code or exceptions...
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.
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.
Use exceptions. Get localized error messages from a resource file or similar. Read this: