什么是适当的异常抛出,如果ODBC驱动程序无法找到抛出、驱动程序、适当、异常

由网友(夸我)分享简介:我有以下的code用于搜索安装了Microsoft Access驱动程序:I have the following code that searches for installed Microsoft Access drivers:var odbcRegKey = Registry.LocalMachine.Ope...

我有以下的code用于搜索安装了Microsoft Access驱动程序:

I have the following code that searches for installed Microsoft Access drivers:

var odbcRegKey = Registry.LocalMachine.OpenSubKey(
    "SOFTWAREODBCODBCINST.INIODBC Drivers", false);
var drivers = new List<string>(odbcRegKey.GetSubKeyNames());
if (drivers.Contains("Microsoft Access Driver (*.mdb, *.accdb)"))
{
    MicrosoftAccessProvider = "Microsoft Access Driver (*.mdb, *.accdb)";
}
else if (drivers.Contains("Microsoft Access Driver (*.mdb)"))
{
    MicrosoftAccessProvider = "Microsoft Access Driver (*.mdb)";
}
else
{
    //TODO: Throw some kind of excception
}

什么是适当的异常抛出,如果它不能找到ODBC驱动程序?没有公共构造 OdbcException ()

推荐答案

如果有疑问,出现InvalidOperationException是我去到的选择。如果这件事情可配置的(也许能够使用的东西比其他访问),考虑ConfigurationException的为好。

When in doubt, InvalidOperationException is my go-to choice. If it's something configurable (perhaps being able to use something other than Access), consider ConfigurationException as well.

阅读全文

相关推荐

最新文章