How to store exception messages
https://softwareengineering.stackexchange.com/questions/128282
-
03-11-2019 - |
Question
How are exception messages commonly stored? for any domain. I'm thinking about this from a maintenance standpoint.
if(!Condition1)
throw new Exception("Some exception");
if(!Condition2)
throw new Exception("Some exception");
If it was decided that the exception message in that snippet needed to be changed, it would have to be changed in two places; leaving it wide open for inconsistent messages and such.
How better to store exception messages then? Perhaps as a static class with constants?
public static Exceptions
{
public const string CONDITION_NOT_MET = "Some exception";
}
...
if(!Condition1)
throw new Exception(Exceptions.CONDITION_NOT_MET);
if(!Condition2)
throw new Exception(Exceptions.CONDITION_NOT_MET);
Are they often (in production) hardcoded?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with softwareengineering.stackexchange