zoukankan      html  css  js  c++  java
  • 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");
                 }
             }
            
        }
    }
    

      

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

  • 相关阅读:
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    Can you answer these queries? HDU
    Count the Colors ZOJ
    Balanced Lineup POJ
  • 原文地址:https://www.cnblogs.com/czyhhxx/p/4477643.html
Copyright © 2011-2022 走看看