Localization of ArgumentException.Message in .NET.

In my localized application, I throw an ArgumentException as follows:

throw ArgumentException("LocalizedParamName", "LocalizedErrorMessage");

And I'll catch him like this:

catch (Exception ex)
{
    Display(ex.Message);
}

I get an error message:

LocalizedErrorMessage Parameter Name: LocalizedParamName

The problem here is: "Parameter Name:", which is written in English, not in my application language. I claim that the string is in the language of the .NET platform. Can anyone confirm this?

A workaround does this:

catch (ArgumentException ex)
{
    Display((ex as Exception).Message  + "\n" + "Translated(Parameter name:)"+ ex.ParamName);
}
catch (Exception ex)
{
    Display(ex.Message);
}

Is there an even more elegant way?

+3
source share
3 answers

, . , . (, " " .) , , , , Foo() Bar(), , . , .

, , , , , , , , .

+3

ArgumentException ( , string paramName) paramName.

, , , , " : yourParamName".

" :" .NET Framework: , , , , , .NET Framework. .

(), , .

ArgumentException ( ) , .

+3
+1
source

Source: https://habr.com/ru/post/1710794/


All Articles