在WPF MVVM应用程序发生异常期间显示用户友好错误消息 [英] Display User friendly error messages during exception in WPF MVVM application

查看:174
本文介绍了在WPF MVVM应用程序发生异常期间显示用户友好错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF MVVM Prism应用程序.我想在异常期间显示对用户友好的错误消息.我需要在整个解决方案中实现这一点.谁能提供给我很好的解决方案,帮助我实现同样的目标?
在此先感谢...

I''ve a WPF MVVM Prism application.I want to display User friendly error messages during exception.I need to implement this in the entire solution. Can anyone provide me good solution that would help me in implementing the same??
Thanks in advance...

推荐答案

我建​​议创建一个带有可选日志记录的错误处理组件.可以通过配置文件,命令行参数或选项菜单打开日志记录,具体取决于您的目标受众以及您希望参与的程度.

其次,当我收到返回的错误错误消息时,我实现的一种解决方案是在SQL Server中创建一个存储过程,该存储过程查询表以获取用户友好的错误消息.

该表包含一个用户友好的错误消息和一个错误消息模式,该错误消息模式将滤除行号等因素.

该模式将利用数据库通配符来过滤消息.例如::%Order%not found%"

存储过程的内容是:

I would recommend creating an error handling component with optional logging available. The logging should be able to be turned on either through the config file, command line parameters or an options menu, depending on your target audience and how much you want to be involved.

Secondly, one solution I implemented when I was getting cryptic error messages returned was to create a stored procedure in SQL Server which queried a table for a user-friendly error message.

The table contained a user friendly error message and a error message pattern which would filter out factors like line number, etc.

The pattern would utilize the database wild card character for filtering messages. For example: :"%Order%not found%"

The meat of the stored procedure is:

SET @RtnMsg = (SELECT TOP 1 SFCErrorMessage FROM SAPErrorMsg WHERE  @Message LIKE  SAPPattern)

SET @RtnMsg = IsNull(@RtnMsg , @Message)



最后,我确定您知道可以在应用程序的App.xaml.cs(或App.xaml.vb)文件中提供默认错误处理程序.我敦促您仅将其用于未处理的错误,而不应将其用作默认错误.

至少包括以下代码:



Finally, I am sure that you are aware that you can supply a default error handler in your application in the App.xaml.cs (or App.xaml.vb) file. I would urge you to only use this for unhandled errors and not as the default.

At a minimum, include the following code:

private void APP_DispatcherUnhandledException(object sender,
    DispatcherUnhandledExceptionEventArgs e)
{
    MessageBox.Show(e.Exception.Message);
    e.Handled = true;
}



希望有帮助,



Hope that helps,
Ray


这篇关于在WPF MVVM应用程序发生异常期间显示用户友好错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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