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始终会执行。

相关文章:

  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
  • 2022-02-14
  • 2022-12-23
猜你喜欢
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2021-07-24
相关资源
相似解决方案