zoukankan      html  css  js  c++  java
  • 异常处理

    using System;
    using System.Collections.Generic;
    using System.Xml.Serialization;
    
    class Program
    {
        static void Main(string[] args)
        {
            Fa().Write();
            Fa().Write();
            Fa().Write();
        }
    
        private static int result = 0;
        static int Fa()
        {
            try
            {
                result++;
    
                return result;
                //throw new Exception("aaaaaaaaa");
            }
            catch (Exception)
            {
                result++;
            }
            finally
            {
                result++;
            }
            return result;
        }
    }
    
    
    
    
    
    
    
    
    
    static class ObjectExt
    {
        public static void Write(this object obj)
        {
            Console.WriteLine(obj);
        }
    
        public static void Write<T>(this IEnumerable<T> obj)
        {
            if (obj is string)
            {
                Console.WriteLine(obj);
                return;
            }
            foreach (var o in obj)
            {
                Console.WriteLine(o);
            }
        }
    }

    2.

    using System;
    using System.Collections.Generic;
    using System.Xml.Serialization;
    
    class Person
    {
        public int Age { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Fa().Age.Write();
            Fa().Age.Write();
            Fa().Age.Write();
        }
    
    
        static Person Fa()
        {
            var p = new Person
            {
                Age = 100
            };
            try
            {
                p.Age++;
                //throw new Exception("");
                return p;
                //throw new Exception("aaaaaaaaa");
            }
            catch (Exception)
            {
                p.Age++;
                return p;
            }
            finally
            {
                p.Age++;
            }
        }
    }
    
    
    
    
    
    
    
    
    
    static class ObjectExt
    {
        public static void Write(this object obj)
        {
            Console.WriteLine(obj);
        }
    
        public static void Write<T>(this IEnumerable<T> obj)
        {
            if (obj is string)
            {
                Console.WriteLine(obj);
                return;
            }
            foreach (var o in obj)
            {
                Console.WriteLine(o);
            }
        }
    }
  • 相关阅读:
    Rust 总章
    GO 总章
    vue引入d3
    echarts地图修改高亮颜色及区域界线颜色
    vue+element 树形穿梭框组件
    element表格上下固定,内容高度自适应
    echarts在dialog弹框中不显示的解决方案
    echarts 饼图给外层加边框
    selenium等待元素出现
    Pycharm永久激活
  • 原文地址:https://www.cnblogs.com/zhaoxianglong1987/p/7686147.html
Copyright © 2011-2022 走看看