C# try catch finally 执行
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始终会执行。
C# try catch finally 执行的更多相关文章
- catch的执行与try的匹配
这里有一段代码: public class EmbededFinally { public static void main(String args[]) { int result; try { Sy ...
- 异常处理 try...catch...finally 执行顺序, 以及对返回值得影响
异常处理 try...catch...finally 执行顺序, 以及对返回值得影响 结论:1.不管有没有出现异常,finally块中代码都会执行:2.当try和catch中有return时,fina ...
- Java中try catch finally执行
直接上代码实例: public static void main(String[] args) { System.out.println(test1()); } static int test1 ...
- try catch finally执行顺序
1.不管有木有出现异常,finally块中代码都会执行: 2.当try和catch中有return时,finally仍然会执行: 3.finally是在return表达式运算后前执行的,所以函数返回值 ...
- try..catch..finally执行顺序return
try..catch..finally这个语法大家都很熟悉,就是捕捉异常.处理异常,面试中经常被问到的一个问题是:如果在try...catch中的某某地方return了,那么之后的某某步骤还会不会执行 ...
- try catch finally 执行顺序面试题总结
在网上看到一些异常处理的面试题,试着总结一下,先看下面代码,把这个方法在main中进行调用打印返回结果,看看结果输出什么. public static int testBasic(){ int i = ...
- 关于try catch块执行流程
代码: package test; public class FinallyTest { public static void main(String[] args) { try { // proce ...
- JAVA代码中加了Try...Catch的执行顺序
public static String getString(){ try { //return "a" + 1/0; return "a"; } catch ...
- try catch finally执行顺序 (return / 变量覆盖)
finally有return 始终返回finally中的return 抛弃 try 与catch中的return 情况1:try{} catch(){}finally{} return x; try{ ...
随机推荐
- Activity传递对象的方法
//Serializeable传递对象的方法 public void SerializeMethod(){ Person mPerson = new Person(); mPerson.setName ...
- application tips
trace(ApplicationDomain.currentDomain == ApplicationDomain.currentDomain); trace(stage.loaderInfo.ap ...
- photoshop,用切片工具等分图片
一,切片 二,导出: 菜单->文件->存储为Web和设备所用格式 将预设改为PNG-24,然后点存储.
- 你能识别这些科技公司的真假logo吗?
快告诉我,不止我一个眼瞎~
- SpatiaLite 各版本数据库差异
SpatiaLite 生成的数据库,3.0版本与4.0版本的表geometry_columns结构发生变化. 这是3.0版本的结构: 这是4.0版本的结构: 主要差别是type和coord_dimen ...
- canvas小知识
清单 1. 绘制 canvas 矩形 function drawRect(){ var canvas = document.getElementById('canvas'); if (canvas.g ...
- 【原创】Linux下编译链接中常见问题总结
前言 一直以来对Linux下编译链接产生的问题没有好好重视起来,出现问题就度娘一下,很多时候的确是在搜索帮助下解决了BUG,但由于对原因不求甚解,没有细细研究,结果总是在遇到在BUG时弄得手忙脚乱得. ...
- 关于jdbc收集
一.如果我这样获得一个resultset ResultSet rs=statment.execquery("select * from tab"我如何能够从resultset中获得 ...
- Drupal如何SQL查询传递参数?
Drupal使用称之为“placeholder”的方式处理SQL查询参数: <?php // WRONG: $result = db_query("SELECT nid, title ...
- bjfu1287字符串输出的大水题
不多说 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> # ...