try

{

  //dosomething eg:

int a = 1;

int b = 2;

int c = a + b;

if(c>2)

{

    return;

}

}

catch(Exception ex)

{

  //dosomething eg:

MessageBox.Show("ERROR:\r\n"+ex.Message);

  return;

}

finally

{

  //dosomething eg:

MessageBox.Show("不管你做了什么,我始终会被执行!");

}

先执行try,如果有异常就执行catch里面的内容,最终执行finally。需要注意的是,无论try 或catch中是否有return,finally始终会执行。

转载于:https://www.cnblogs.com/programsky/p/4218040.html

C# try catch finally 执行相关推荐

  1. catch的执行与try的匹配

    这里有一段代码: public class EmbededFinally { public static void main(String args[]) { int result; try { Sy ...

  2. Promise—关于catch(你真的了解catch的执行顺序吗)

    一.问题 今天突然被同事问到一个问题,以下代码怎么输出: Promise.all([new Promise(res => res(0)), new Promise((res, rej) => ...

  3. RuntimeException的特殊情况[C++] 有人会在程序中try catch吗?什么样的问题需要用try catch语句执行

    http://www.bitscn.com/pdb/java/200605/23824.html 本章的第一个例子是: if(t == null) throw new NullPointerExcep ...

  4. try catch嵌套执行顺序测试

    分享一段测试try catch 执行顺序和那些代码后续执行,那么不执行的代码: @Testpublic void testTryCatch(){try {System.out.println(&quo ...

  5. try { } catch{ } finally{ } 执行顺序总结

    publicclass TestTry { publicstaticvoid main(String[] args) { TestTry t = new TestTry(); System.out.p ...

  6. try catch finally执行顺序_技术大佬:我去,你竟然还在用 try–catch-finally

    二哥,你之前那篇 我去 switch 的文章也特么太有趣了,读完后意犹未尽啊,要不要再写一篇啊?虽然用的是 Java 13 的语法,对旧版本不太友好.但谁能保证 Java 不会再来一次重大更新呢,就像 ...

  7. 细琢磨,try catch finally 执行顺序与返回值

    try catch finally 常见格式如下: try{//应用代码}catch(Exception e){//异常捕捉处理}finally{//资源释放.流关闭等等 } 通常执行顺序: try有 ...

  8. try catch finally 执行顺序问题

    public static void main(String[] args) {System.out.println(abc());}public static Integer abc(){Syste ...

  9. python try catch finally执行顺序_对python中的try、except、finally 执行顺序详解

    如下所示: def test1(): try: print('to do stuff') raise Exception('hehe') print('to return in try') retur ...

最新文章

  1. 炸裂!Google这波操作,预警了什么?
  2. SSM高级整合项目实战
  3. spring tx:advice 和 aop:config 配置事务
  4. 百度Create2021:百度地图日均位置服务请求次数突破1300亿
  5. Java Array.sort的六种常用方法总结
  6. 小创意,大世界——休闲游戏开发者指南
  7. Tag标签的增加和删除功能
  8. [leetcode]190. 颠倒二进制位
  9. ArcMAP TIN与栅格DEM的坡度坡向对比分析
  10. zabbix 3.0.7 for Centos 7.2 安装
  11. 【WPS·Excel】数据分析方法汇总
  12. 这8种常用的代码编辑器,你平时用哪个?
  13. Win7 关闭触摸屏 屏幕键盘功能
  14. EPIC/Steam 手柄没反应问题解决办法
  15. threejs 绘制星空
  16. 海康摄像头录像回放功能
  17. python的turtle的画太阳花(简洁和经典)
  18. android中java中的开方
  19. 审车的时候环保怎样安全通过_车审环保过不了如何处理
  20. 相机快门和曝光时间的确定

热门文章

  1. Spread for Windows Forms快速入门(2)---设置Spread表单
  2. HS_300_PE.csv
  3. fancy approach for making your code listed used for short essays, no need for listing in outline
  4. 《大红包》电影观后感
  5. 高手不得不知的Java集合List的细节
  6. [Leetcode]160. Intersection of Two Linked Lists
  7. 天水市荣膺“2016中国智慧城市创新奖”
  8. shell批量监控网站状态码
  9. Mac OS Sierra安装Imagick
  10. Task Runner Explorer for vs2015找不到啊