zoukankan      html  css  js  c++  java
  • 原来···是不是高手,看try cathch都能看出来···

    先看一段代码:
    View Code
     1     internal class ThrowAndThrowEx
    2 {
    3 public static void Test ()
    4 {
    5 Class1.DoSomething();
    6 }
    7 }
    8
    9
    10 public class Class1
    11 {
    12 public static void DoSomething ()
    13 {
    14 try
    15 {
    16 Class2.DoSomething();
    17 }
    18 catch (Exception ex)
    19 {
    20 //throw;
    21 throw new Exception("class1 call class2", ex);
    22
    23 }
    24 }
    25 }
    26
    27
    28 public class Class2
    29 {
    30 public static void DoSomething ()
    31 {
    32 try
    33 {
    34 Class3.DoThrowOrThrowEx();
    35 }
    36 catch (Exception ex)
    37 {
    38 throw;
    39 //throw ex;
    40 }
    41 }
    42
    43
    44 }
    45
    46
    47 public class Class3
    48 {
    49 public static void DoThrowOrThrowEx ()
    50 {
    51 try
    52 {
    53 int divider = 0;
    54 int number = 5 / divider;
    55 }
    56 catch (Exception ex)
    57 {
    58 throw ex;
    59 //throw;
    60 }
    61 }
    62
    63 }

    如此来看 

    可以在一些关键的分层次的地方使用:

                    throw new Exception("class1 call class2", ex);

    其他地方使用:

                    throw;



  • 相关阅读:
    单例模式
    pandas to_html
    restful
    numpy版本查看以及升降
    视频下载
    转载:caffe中的Reshape层
    caffe编译报错解决
    python 版Faster Rcnn
    转载:动态规划以及路径记录
    TensorFlow设置GPU占用量
  • 原文地址:https://www.cnblogs.com/scottgu/p/2244498.html
Copyright © 2011-2022 走看看