开发者

How to get Notify the application with error in the DataBase (e.g. StoredProcedure, view etc etc)

I am ask a q开发者_运维问答uestion in Interview that we are developing a WPF application which calls some StoredPeocedure. If there is an error in StoredProcedure during execution or any error occur in database how do we now in application and show this gracefully to the client.

Means the error is in SQl on Server and application should be aware of it that how to show that one.

I answer to use try catch statement but the interviewer did not accept that answer. I google it but could not get any answer.

can anyone tell me the suitable way to do this?


Well, try/catch by itself doesn't really do much, and it would certainly be bad practice to present a UI dialog from your DAL/DB/repo layer. I would:

  • in the DAL catch the expected SQL exception and throw a documented exception that the UI can expect
  • in the UI layer, catch the exception you threw and present a suitable dialog to the user

Of course, your UI should really expect to catch any exception in this scenario; simply it might put a friendlier face on an expected (predictable) exception - and be more cautious in the case of something it didn't expect.

An even better answer would be: verify your scenario up-front, so that you don't expect an exception at all - then any exception is exactly that: exceptional.

As a general point though: never be afraid to ask the interview what they had in mind; you might then be able to discuss the merits (and not) of each approach. Also, never assume that the interviewer knows everything. I would have absolutely no qualms telling an interviewer (nicely, mind) that they are mistaken about a technical point. It might be sneaky, but the interviewer might actually be looking for someone who isn't afraid to speak up when someone makes a technical error, and is therefore injecting subtle gibberish into technical discussions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜