0

I am developing in a machine set in Japanese. I am trying to set the exceptions to English and I found this method

It works well- by setting the culture to English I can have my exceptions thrown in English and not the local language.

My question is, this settings is for the application I am working on, but if this application calls a library and this library produces exceptions, will the exceptions appear in english? (The library was built in this culture system and I don't think the culture is changed at all)

Thanks for any comment on this topic

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • 2
    Are you talking about any particular "library"? Because not every library respects culture for exception messages and definitely minority have exceptions localized for every language. – Alexei Levenkov Jan 31 '18 at 01:48
  • The library in question has not set any culture- so I guess uses japanese by default. If I use this library in an application and the library throws exceptions (catched by the application) will they be in japanese? (the application culture is set to english) – KansaiRobot Jan 31 '18 at 05:20

1 Answers1

0

Changing current culture (How to change CurrentCulture at runtime?) may impact exception messages but it will also change normal code behavior. Consider doing so only for debugging.

Most of the code does not bother with localizing exceptions and simply have hardcoded strings as error messages. Smaller number of libraries will use localizable resource strings for all or just potentially user-facing exceptions but unlikely to localize in many languages. Even smaller number will have all exceptions localized for all languages (I believe Microsoft have all .Net Framework libraries localized for all languages).

So unless if library you are concerned about is from that smaller set with localized exceptions there is nothing you can do to change exception text. You can usually quickly experiment with it by writing code that is setting current culture (CurrentCulture and CurrentUICulture) to language you are interested in and triggering particular exception. Or you can decompile code and see if exception messages are hardcoded.

Instead of changing culture I would catch more specific exceptions and write code to handle them especially if library produces information shown to user or handles any serialized data.


Warning: changing current culture will modify behavior of all string parsing and formatting functions. So if code you call tries to read or write any documents/settings or produces any UI strings I'd be very concerned with changing current culture.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179