• 异常处理


    不要进行无意义的try....catch,只在真的需要catch的地方再处理。应彻底在测试阶段就消灭异常。

    代码中没有必要每个地方都try...cvatch 

    程序中出现未处理的异常会直接退出,每个地方都try ,,..catch....太麻烦,可以在App中处理      DispatcherUnhandleException

    新建一个窗体App .xaml.代码如下:

    <Application x:Class="HRMSys.UI.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 StartupUri="MainWindow.xaml" DispatcherUnhandledException="Application_DispatcherUnhandledException">
        <Application.Resources>
             
        </Application.Resources>
    </Application>

     在App .xaml.cs中添加代码如下:

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Windows;
    
    namespace HRMSys.UI
    {
        /// <summary>
        /// App.xaml 的交互逻辑
        /// </summary>
        public partial class App : Application
        {
            private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
            {
                //在Application_DispatcherUnhandledException中集中处理异常
                MessageBox.Show("程序中出现了严重错误,请联系系统开发商!"+e.Exception.Message);
                e.Handled = true;
            }
        }
    }

    完毕!

  • 相关阅读:
    spring boot基础知识
    使用PrintDocument定制打印格式
    vue刷新页面出现闪烁
    递归限制级数
    导出Excel的2个方法
    通过反射获取对象名称和值
    asp.net mvc 使用bootstrap的模态框插件modal
    记录用到的mssql的几个方法
    记录几个字符串转html的帮助类,以防忘记
    git 命令
  • 原文地址:https://www.cnblogs.com/qiushuixizhao/p/3244820.html
Copyright © 2020-2023  润新知