try catch块后的代码语句 [英] code statements after try catch block

查看:126
本文介绍了try catch块后的代码语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用try catch块来处理异常并显示相应的消息,但是在catch块之后,我正在使用另一个必须在没有异常的情况下执行的语句.
如果没有异常,则catch块之后的语句必须执行
如何完成该任务

谢谢inadvance

Hi,

am using try catch block to handle the exceptions and display the appropriate message but after catch block am using another statements which had to execute if there is no exception.
if there is no exception then the statement after catch block has to execute
how to do that task

thanks inadvance

推荐答案

接受一个布尔变量并将其初始化为false,如果发生异常,则将其设置为true.看下面的例子.
Take a Boolean variable and initialize it false, if exception happens then set it to true. look at the example below.
bool IsexceptionHappened = false;

try
{
   //Your code here
}
catch()
{
   IsexceptionHappened = true;
   // Exception Message here 
}

if(IsexceptionHappened == false)
{
     // Next code here
     // Suppose its again try catch then
     try
     {
          ....
      }
     catch()
     {
          IsexceptionHappened = true;
          // Exception Message here 
     }       
}

if(IsexceptionHappened == false)
{
     // Next code here
}



您可以应用这样的逻辑



You can apply logic like this


这篇关于try catch块后的代码语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆