处理错误代码

编程入门 行业动态 更新时间:2024-10-09 15:18:01
本文介绍了处理错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的应用程序发生异常时,我需要根据我需要的错误代码将错误代码从业务层 传递到Presentation层显示数据库中可用的消息。 我想知道如何传递并获取表示层中的错误代码。 用于记录我正在使用的异常log4net和企业库4.0。 提前致谢

Hi, In my application when exception occurs i need to pass the Error Code from the Business Layer to the Presentation layer here based on the error code i need to show the message that is available in the DB. I want to know how to pass and get the Error code in the Presentation Layer. For logging Exceptions i am using log4net and Enterprise library 4.0. Thanks in advance

推荐答案

使用您自己的例外。创建从System.Exception或System.ApplicationException或其他继承的适当异常类,并添加您的ErrorCode属性。在业务层中适当时抛出异常。在表示层中,你需要一些try ... catch块,当你捕获一个特定的异常时,你可以访问它的错误代码并获得它的措辞。 注意你可以尝试后有多个catch块,最具体的例外必须先行: Use your own Exceptions. Create appropriate exception classes inheriting from System.Exception or System.ApplicationException or other, and add your ErrorCode property. Thrown the exception when appropriate in the Business Layer. In the Presentation Layer, you need some try...catch blocks, and when you catch one of your specific exceptions, you can access its error code and get the wording for it. Note that you can have multiple catch blocks after a try, the most specific exception has to come first: try { ...some code } catch (MyException mex) { string msg = GetMessage(mex.ErrorCode); ... } catch (System.Exception ex) { ... }

更多推荐

处理错误代码

本文发布于:2023-11-28 03:45:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640825.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!