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
scroll top