try-catch-finally
来源:互联网 发布:淘宝导航栏半透明代码 编辑:程序博客网 时间:2024/06/05 05:47
通过中间代码窥探try-catch-finally本质:
class Program { static void Main(string[] args) { Program p = new Program(); Console.WriteLine(p.Test1()); //Console.WriteLine(p.Test2()); Console.Read(); } //结果为:3 private TestClass Test1() { TestClass tc = new TestClass(); try { tc.testVar = 2; return tc; } catch (Exception) { throw; } finally { tc.testVar = 3; } } //结果为:2 private int Test2() { int test = 1; try { test = 2; return test; } catch (Exception) { throw; } finally { test = 3; } } } class TestClass { public int testVar = 111; public override string ToString() { return testVar.ToString(); } }
调用方法Test2,try中return时,已经将返回值保存在中间代码的本地变量中,而不再是源码中变量test,所以finally的操作是无效的。其中间代码为:
2 1
- try..catch..finally
- try-catch-finally
- Try-catch-finally机制
- 关于try-catch-finally
- C# try catch finally
- try...catch...finally
- try catch finally用法
- Try ---Catch----Finally
- try...catch... finally
- try....catch...finally 妙用
- try{} catch(){}finally{}执行
- Try Catch Finally
- try-catch-finally
- C# try, catch ,finally
- try catch finally
- try catch finally
- try-catch-finally
- try...catch...finally
- iOS常用设计模式——工厂方法(简单工厂模式,工厂方法模式, 抽象工厂模式)
- GC启动agent失败
- 生成式学习算法
- windows运行命令
- 算法——字符串匹配之朴素算法
- try-catch-finally
- mybatis resultMap报错
- 冒泡排序算法
- GrideView
- 安卓新手开发学习小技巧
- wordpress变更域名
- Sublime Text 新建文件的模版插件: SublimeTmpl
- Eclipse快捷键
- 基于Nutch+Hadoop+Hbase+ElasticSearch的网络爬虫及搜索引擎