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);
            }
        }
    }
  • 相关阅读:
    java坏境内存不够用 大量占用swap 临时加swap
    磁盘分区
    简述raid0,raid1,raid5,raid10 的工作原理及特点
    给用户提权
    用户的环境变量被删除了
    定时任务
    linux权限
    kafka部署
    数据仓库
    kylin
  • 原文地址:https://www.cnblogs.com/zhaoxianglong1987/p/7686147.html
Copyright © 2011-2022 走看看