I need to change specific system exception message with my custom one.
Is it bad practice to catch an exception and inside the catch block check if the system exception message matches a specific string and if so, throw my custom exception?
try
{
...
}
catch (System.Security.Cryptography.CryptographicException ex)
{
if (ex.Message.Equals("The specified network password is not correct.\r\n", StringComparison.InvariantCultureIgnoreCase))
throw new Exception("Wrong Password");
else
throw ex;
}
Or is there a better way to achieve this.
if(ex.Message == "...")will only work for English locales.en.