views:

78

answers:

2

(Asked by @tomhollander on Twitter) What's the most appropriate exception to throw if a required app/web.config configuration setting is not present?

+4  A: 

System.Configuration.ConfigurationException

According to MSDN (emphasis added by me):

The ConfigurationException exception is thrown if the application attempts to read or write data to the configuration file but is unsuccessful. Some possible reasons for this can include malformed XML in the configuration file, file permission issues, and configuration properties with values that are not valid.

Jeff Fritz
+1  A: 

ConfigurationException is obsolete. The docs say it's been replaced by ConfigurationErrorsException, but this is designed to convey failures in the configuration system - I don't believe it's intended to show problems such as missing or malformed configuration values.