如何在C#中显示正确的sqlite异常消息? [英] How do I display proper sqlite exception messages in C#?
本文介绍了如何在C#中显示正确的sqlite异常消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要自定义我的错误消息,例如'Unique Constrain Failed'和'Table not exists'异常。我该怎么做?
我尝试过:
I need to customize my error messages like the 'Unique Constrain Failed' and the 'Table does not exist' exception. How do I do this?
What I have tried:
catch (SQLiteException ex)
{
MessageBox.Show("Error "+ex);
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
}
产生太多技术错误,这会让用户感到困惑。我不希望我的用户看到任何错误,但如果他们这样做,我希望他们看到正确的错误。如何检查SQLiteException捕获的错误类型?
Gives too much technical errors which will confuse users. I do not expect my users to see any errors but if they do, I want them to see proper ones. How do I check which type of error is caught by the SQLiteException?
推荐答案
SqLite使用错误代码,SqLiteConnection,SqLiteCommand等类转换为异常。话虽如此,SqLiteException类会向您的应用返回错误代码: SqliteException.SqliteErrorCode Property [ ^ ] - 这样您就可以用它来确定问题所在并向您报告用户。
有一张表这里 [ ^ ]命名错误代码。
SqLite uses error codes, which the SqLiteConnection, SqLiteCommand, and suchlike classes convert into Exceptions. Having said that, the SqLiteException class returns teh error code to your app: SqliteException.SqliteErrorCode Property[^] - so you can use that to determine what the problem is and report that to your users.
There is a table here[^] which "names" the error codes.
这篇关于如何在C#中显示正确的sqlite异常消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文