Forum Discussion

GypsyPrince's avatar
GypsyPrince
Copper Contributor
Feb 23, 2025

Specify locale/language for exception messages to user during runtime.

I am using VB 2022 with .NET 8 & 9. I develop applications that allow the user to specify which language they want the GUI elements to be displayed in while the application is running - regardless of what language the users' MS Windows profile is set to.

The reason I do this is because some companies (mine included) require all systems to be set to the U.S. English (EN-US) regional/locale settings. This is very easy for me to achieve, even for expected user errors which I can head off. However, unexpected system error messages are always displayed in the English language because the system is set to the English language. Is there any known way to force unexpected error/exception messages to be displayed in a language other than the system's current language?

 

If I knew every single possible error that could be thrown up, as well as its corresponding error code/number, I could create translations myself. But, unfortunately, I have no way of listing every possible system error that could be thrown up during runtime. It would be nice if Microsoft had a COMPLETE list of these somewhere. But every list I've seen is fragmented and incomplete, and sometimes doesn't include a corresponding error code with the message.

 

Try 'Attempt the following block of code.
     '///////////////////////////////////////////////
     ' E X E C U T E   S O M E   C O D E   H E R E !
     '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Catch e As System.Exception 'Trap any unexpected system error.
     MessageBox.Show(e.HResult.ToString & NewLine & e.Message, MyCaption, MessageBoxButtons.OK, MessageBoxIcon.Error) 'Display the error message to the user.
End Try

 

Even though the user's system is set to the English language, I want to be able to display the message passed in the 'e.Message' member from the codes sample in whatever language the user has specified their GUI to display in during that application's runtime.

Any ideas how to achieve this?

BTW...  the ability to do this would be an AWESOME feature for Microsoft to add to future .NET releases.

No RepliesBe the first to reply

Resources