I have an application which tries to load some expected registry settings within its constructor.
What is the most appropriate .NET Exception from the BCL to throw if these (essential, non-defaultable) registry settings cannot be loaded?
For example:
RegistryKey registryKey = Registry.LocalMachine.OpenSubkey('HKLM\Foo\Bar\Baz'); // registryKey might be null! if (registryKey == null) { // What exception to throw? throw new ???Exception('Could not load settings from HKLM\foo\bar\baz.'); }
I’d go with ArgumentException or ArgumentOutOfRangeException..
Quoting MSDN:
…
IMO writing a proper exception message is more important.