惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
Spread Privacy
Spread Privacy
Scott Helme
Scott Helme
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
博客园 - 叶小钗
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
量子位
Security Latest
Security Latest
P
Proofpoint News Feed
P
Privacy International News Feed
P
Palo Alto Networks Blog
D
DataBreaches.Net
大猫的无限游戏
大猫的无限游戏
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google Online Security Blog
Google Online Security Blog
Webroot Blog
Webroot Blog
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
Vercel News
Vercel News
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Hugging Face - Blog
Hugging Face - Blog
月光博客
月光博客
Hacker News - Newest:
Hacker News - Newest: "LLM"
K
Kaspersky official blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Stack Overflow Blog
Stack Overflow Blog
AWS News Blog
AWS News Blog
博客园 - Franky
爱范儿
爱范儿
T
Tor Project blog
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
小众软件
小众软件
L
LINUX DO - 最新话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
W
WeLiveSecurity
SecWiki News
SecWiki News
L
LangChain Blog
I
InfoQ

博客园 - Gofficer

决战紫禁之巅 为学 C#网页自动登录和提交POST信息的多种方法 一个C#写的调用外部进程类 快速实现在Windows应用程序中支持拖拽的TreeView控件(C#) PPT转图片 开发人员,敢问路在何方? C# 实现注销、关机、重启电脑功能 ultraGrid 控件中,实现单元格内容换行显示 如何用一条sql取得第10到第20条的记录? 用Sandcastle一键生成CHM帮助文档 实现服务器端与客户端对话 C#中访问WEB页面 使用代理服务器 自定义Ping方法 HTTP请求和应答 Socket套接字实现服务器端连接 Socket套接字实现客户端连接 启动和停止本地系统进程
异常处理
Gofficer · 2007-08-24 · via 博客园 - Gofficer

  1using System;
  2using System.Drawing;
  3using System.Collections;
  4using System.ComponentModel;
  5using System.Windows.Forms;
  6using System.Data;
  7using System.Threading;
  8
  9namespace Exception
 10{
 11    /// <summary>
 12    /// 异常处理。
 13    /// </summary>

 14    public class Form1 : System.Windows.Forms.Form
 15    {
 16        private System.Windows.Forms.Button button1;
 17        private System.Windows.Forms.Button button2;
 18        private System.Windows.Forms.Button button3;
 19        /// <summary>
 20        /// 必需的设计器变量。
 21        /// </summary>

 22        private System.ComponentModel.Container components = null;
 23
 24        public Form1()
 25        {
 26            //
 27            // Windows 窗体设计器支持所必需的
 28            //
 29            InitializeComponent();
 30
 31            //
 32            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
 33            //
 34        }

 35
 36        /// <summary>
 37        /// 清理所有正在使用的资源。
 38        /// </summary>

 39        protected override void Dispose( bool disposing )
 40        {
 41            if( disposing )
 42            {
 43                if (components != null
 44                {
 45                    components.Dispose();
 46                }

 47            }

 48            base.Dispose( disposing );
 49        }

 50
 51        Windows Form Designer generated code
109
110        /// <summary>
111        /// 应用程序的主入口点。
112        /// </summary>

113        [STAThread]
114        static void Main() 
115        {
116            Application.Run(new Form1());
117        }

118        class MyException:ApplicationException
119        {
120            public MyException(String msg):base(msg)
121            {
122                HelpLink = "http://NotARealURL.Microsoft.com/help.html";
123            }

124        }

125        public void ShowException(System.Exception ex)
126        {
127            string str;
128            str = string.Format("Exception:\n\t{0}\n", ex.GetType().ToString());
129            str += string.Format("Message:\n\t{0}\n", ex.Message);
130            str += string.Format("Stack Trace:\n\t{0}\n", ex.StackTrace);
131            str += string.Format("Help Link:\n\t{0}\n", ex.HelpLink);
132            MessageBox.Show(str);
133        }

134        // 除以 0 异常。
135        private void button1_Click(object sender, System.EventArgs e)
136        {
137            int x = 0;
138            try
139            {
140                // 产生异常。
141                x = 10 / x;
142            }

143            catch(System.Exception ex)
144            {
145                ShowException(ex);
146            }

147        }

148        // 无效对象异常。
149        private void button2_Click(object sender, System.EventArgs e)
150        {
151            object a = null;
152            try
153            {
154                MessageBox.Show(a.ToString());
155            }

156            catch(System.Exception ex)
157            {
158                ShowException(ex);
159            }

160        }

161        // 自定义异常。
162        private void button3_Click(object sender, System.EventArgs e)
163        {
164            try
165            {
166                throw(new MyException("这是我自己定义的异常。"));
167            }

168            catch(System.Exception ex)
169            {
170                ShowException(ex);
171            }

172        }

173    }

174}

175