.NET: Which Exception to Throw When a Required Configuration Setting is Missing?

Personally, I’d use InvalidOperationException, as it’s a problem with the object state – not the configuration system. After all, shouldn’t you allow these settings to be set by code and not config as well? The important part here is not that there was no line in app.config, but that a required piece of info was not present.

To me, ConfigurationException (and it’s replacement, ConfigurationErrorsException – despite the misleading MSDN docs) are for errors in saving, reading, etc. of Configuration.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)