views:

126

answers:

3

hi. i am developing a multilingual application in which i have to consider different errors..

suggest me whether i use error code or exceptions...

A: 

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.

dbemerlin
Wouldn't in be better if other exceptions still inherit from System.Exception class?
Igor Korkhov
If TranslatedException inherits from the base Exception (depends on the programming language wich was not specified by the OP) then other Exceptions can safely inherit from TranslatedException without breaking any of the (bad-style) catch (Exception ex) code.
dbemerlin
i can get the respective translation from resource file. but i just wants to know that whether I use exceptions of use error codes.
Mohsan
+2  A: 

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.

naivists
+1 for simplicity. Simple is good.
Walter
A: 

Use exceptions. Get localized error messages from a resource file or similar. Read this:

Svish