Exceptions

大作业好烦,烦的我都写不下博客了==。

首先要认识到:

1.Bugs & errors 应该是由程序自身来解决。

2.对于可预测但不可避免的问题使用exception 处理。

关于异常处理的顺序如下

如果在相应方法中找到处理Exception的代码段,

就会调用它对Exception进行处理。

如果没有找到会展开调用栈,到上一层找相应的Exception处理程序。

如果在返回到Main时仍没有找Exception处理程序。

系统CLR会使用DEFAULT Exception处理.

(终止程序/或在debug状态给出”有未被处理的EXCEPTION”)。

日常贴代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
         {
             try
             {
                 Level3();
             }
             catch
             {
                 Console.WriteLine("Main in catch");
             }
         }
 
         static void Level3()
        {
             try
             {
                 Console.WriteLine("Level3 in try");
                 Level2();
             }
             catch
             {
                 Console.WriteLine("Level3 in catch");
                 throw;
             }
             finally
             {
                 Console.WriteLine("Level3 in finally");
             }
         }
 
         static void Level2()
         {
             try
             {
                 Console.WriteLine("Level2 in try");
                 Level1();
             }
             catch
             {
                 Console.WriteLine("Level2 in catch");
                 throw;
             }
             finally
             {
                 Console.WriteLine("Level2 in finally");
             }
         }
 
         static void Level1()
         {
             try
             {
                 Console.WriteLine("Level1 in try");
                 throw new Exception("Level1");
             }
             catch
             {
                 Console.WriteLine("Level1 in catch");
                 throw;
             }
             finally
             {
                  Console.WriteLine("Level1 in finally");
             }
         }
        
    }
}

  

好的,就这样我又写完了一篇博客

转载于:https://www.cnblogs.com/czyhhxx/p/4477643.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值