开发者

try catch in C# WPF app

HI all, I have a WPF based POS software and have more than 100 Stored procedure in SQL Server 2005 Express Database. I am using DAL for database connectivity. This app is designed to be able to bill from LAN clients so ConnectionString points to Database server IP. For this reason I have called all SP (and related logic like displaying data on gridview etc.) in try catch block. Will this slow down my app, Is extensive use or try catch not good for any app.

Can you suggest me any other way to handle error from LAN client DB connect开发者_JAVA技巧ivity.

Thank you RAJ K


No, try/catch is not necesarily slow unless an exception is actually thrown. And since you should only have exceptions in exceptional circumstances, there should be little impact on the performance of your program due to the use of try/catch.


In my opinion, trycatch should always be used to handle errors you cant forsee (like files or connection manipulation). If it is something you can control (like X character in a string), this should be done via validations.

About the speed, I dont think it slow it down.


Using try/catch blocks won't appreciably slow down your application. I suspect you would be well served by using transactions on your database, as well.


It will not slow down the performance in this context. It would slow down if you called the function containing try/catch 1000 of times repeatedly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜