Is it possible to show exception message in en-BR?

Asked

Viewed 407 times

6

I would like my exception message to be shown in English, someone would know how?

catch (Exception ex)
{
  Debug.Writeline(ex.Message);
}

1 answer

6


Besides not being good at catching Exception I talk about it in several questions here, the ideal is to do something useful when capturing an exception. Showing the exception raw text to the user is not usually considered something very useful. In general these messages are made to inform the programmer and not the user.

If you still want to do this, change the culture of thread:

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("pt-BR");

If Windows does not have the Portuguese packages installed, then it gets more complicated, you would have to do it manually.

Behold nay working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference. But here’s how to test if it worked.

  • Thank you for the reply when you refer to "not be good to catch" exception, refers only to generic or any one, for example, specific ones such as FileNotFoundException ?

  • 1

    Generic ones. Although depending on the context any exception may be generic :) What you need is to capture as specific as possible. It may even be the Exception, but I only see one case to do this.

  • The documentation does not recommend CA1031: Do not catch general Exception types (https://msdn.microsoft.com/en-us/library/ms182137.aspx )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.