zoukankan      html  css  js  c++  java
  • Exception处理机制

     1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5
    6 namespace ConsoleApplication2
    7 {
    8 class Program
    9 {
    10 static void Main(string[] args)
    11 {
    12 //Level1
    13 try
    14 {
    15 //Level2
    16 try
    17 {
    18
    19 //Level3
    20 try
    21 {
    22 //throw new ExceptionA("Exception in Level3");
    23 //throw new ExceptionB("Exception in Level3");
    24 }
    25 catch (ExceptionA)
    26 {
    27 Console.WriteLine("Level3中处理Exception");
    28 }
    29 finally
    30 {
    31 Console.WriteLine("Level3中的finally语句块");
    32 }
    33 throw new ExceptionC("Exception in Level2");
    34 }
    35 catch (ExceptionB)
    36 {
    37 Console.WriteLine("Level2中处理Exception");
    38 }
    39 finally
    40 {
    41 Console.WriteLine("Level2中的finally语句块");
    42 }
    43 //throw new Exception("Exception in Level1");
    44 }
    45 catch (ExceptionC)
    46 {
    47 Console.WriteLine("Level1中处理ExceptionC");
    48 }
    49 catch (Exception)
    50 {
    51 Console.WriteLine("Level1中处理Exception");
    52 }
    53 finally
    54 {
    55 Console.WriteLine("Level1中的finally语句块");
    56 }
    57
    58
    59 Console.ReadKey();
    60
    61 }
    62 }
    63 }
     1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5
    6 namespace ConsoleApplication2
    7 {
    8 class ExceptionA : Exception
    9 {
    10 public ExceptionA(string mess):base(mess)
    11 {
    12 }
    13 }
    14 }

    首先在同级查找是否存在兼容的异常,如果没有,则一级一级往上

  • 相关阅读:
    线程池及其原理和使用
    多线程通信Queue
    Condition实现线程通信
    守护线程和锁
    习题 7:更多的打印
    习题 6:字符串和文本
    习题 5:更多的变量和打印
    习题 4:变量和命名
    习题 3:数字和数学计算
    习题 2:注解和#号
  • 原文地址:https://www.cnblogs.com/changweihua/p/2171980.html
Copyright © 2011-2022 走看看