Last post Nov 06, 2006 08:23 AM by Syc0F3ar
Nov 03, 2006 08:20 AM|Syc0F3ar|LINK
I am looking for the best way to handle exception messages in a multi-language site. I understand how resources work and I can get the message of the exception from the resource file without a problem. The problem I am having is the way the language is
choosen for the exception message. From my understanding, exceptions in general are not for the general user to see. Not even the exception message. No user out there should get and error saying "Object reference not set to an instance of an object." or
a foreign key constraint error from the database. To me, those exception messages are for us as developers to use to determine what the problem is. If it has to do with the information entered, we add code to check that and if it is invalid, display a meaning
message to the user so the exception does not even occur. Or we catch the exception and write code to display the information to the user correctly. Now where my problem comes in is when dealing with multiple languages. I have a site that may have English,
German, French, etc... as available languages on my site. So I need to set the CurrentUICulture to the correct Culture so the resources for the correct language is used. But I don't want my exceptions to be in French or German. I want them to be in English.
So I don't want the CurrentUICulture to be used, which is what happens in all of the built in exceptions in the framework. This application is designed to be sold and installed along with an API so other developers can use the application, so I do need to
exception messages to support different languages, just not necessarily what the ui culture is.
So basically what I am asking is if there is currently a way to set the culture for the exceptions to be different the the current UI culture?
Nov 03, 2006 01:34 PM|vivek_iit|LINK
Though I am not very clear with the way you explained your scenario It seems you want your API users to see the thrown exceptions in English language, irrespective of the culture, then I think you need to focus on thrown exceptions by the lower layers as
all exceptions which are caught by the GUI will be handled and a user friendly message in the custom language will be shown to them. For exceptions simply thrown, you should not set the culture at all (I am assuming these classes would be in a separate layer,
like BL class library).
All exceptions handled by the GUI will use resource files, but API users should get exceptions in default culture only.
Nov 03, 2006 01:47 PM|Syc0F3ar|LINK
Nov 03, 2006 01:59 PM|vivek_iit|LINK
That is not true. Any exception, no matter where it is thrown or caught, uses the CurrentUICulture of the thread. If you use reflector and look at the implementation of the constructor of ArgumentNullException you will see what I mean. It pulls the message
from the resource file using the CurrentUICulture from the thread.
That's true but I do not know how your app is structured. I thought that the culture settings are all in the GUI and if the users are using your library dll's they are not concerned with the GUI at all. So they should be receiving the errors in the default
culture as the current thread's culture is not set by your GUI. It's upto them to choose their culture.
Let me know your thoughts here.
Nov 03, 2006 04:47 PM|Syc0F3ar|LINK
Nov 04, 2006 04:13 AM|vivek_iit|LINK
> So basically what I am asking is if there is currently a way to set the culture for the exceptions to be different the the current UI culture?
As far as I know, the answer to the question above is "no". But why would you want the exceptions to be in English? Suppose someone has German locale set and using your app, he should ideally get exceptions in German only.
Nov 06, 2006 08:23 AM|Syc0F3ar|LINK