什么是适当的异常抛出,如果ODBC驱动程序无法找到 [英] What is the proper exception to throw if an ODBC driver cannot be found

查看:161
本文介绍了什么是适当的异常抛出,如果ODBC驱动程序无法找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

var odbcRegKey = Registry.LocalMachine.OpenSubKey(
    "SOFTWARE\\ODBC\\ODBCINST.INI\\ODBC 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.

这篇关于什么是适当的异常抛出,如果ODBC驱动程序无法找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆