多次尝试一次捕获可能吗? [英] Multiple Try ane One catch are Possible?

查看:97
本文介绍了多次尝试一次捕获可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多次尝试一次捕获可能???????

解决方案

否。

您可以有多个 catch 块有一个尝试但你不能有多个尝试只有一个 catch 的块,比你写的更多:

  if (a == b)
{
DoSomething();
}
DoAnotherSomething();
else
{
DoSomethingElse();
}

catch 块必须紧跟结束阻止它适用,或者系统不知道你要做什么。


不是直接的,但是你可以用这样的方法总结异常处理代码:

 HandleException(例外e)
{
// 做任何事情似乎是合理的例外。
}

// 某处
尝试
{
// 抛出异常的东西
}
catch (SophisticatedException ex)
{
HandleException(ex);
}

// [..]

尝试
{
// 其他一些东西,也抛出异常
{
catch (SophisticatedException ex)
{
HandleException(ex);
}


没有你不能使用多个尝试使用一个Catch,尝试使用多个try并按下双选项卡按钮它将自动创建try catch块

Multiple Try ane One catch are Possible???????

解决方案

No.
You can have multiple catch blocks with a single try but you can't have multiple try blocks with a single catch, any more than you can write:

if (a == b)
  {
  DoSomething();
  }
DoAnotherSomething();
else
  {
  DoSomethingElse();
  }

The catch block(s) must immediately follow the end of the try block it applies to, or the system doesn't know what you are trying to do.


Not directly, but you could sum up the exception handling code in a method like this:

HandleException(Exception e)
{
    // Do whatever seems reasonable with the exception.
}

// Somewhere
try
{
    // Something that throws an exception
}
catch(SophisticatedException ex)
{
    HandleException(ex);
}

// [..]

try
{
    // Some other thing, also throwing an exception
{
catch(SophisticatedException ex)
{
    HandleException(ex);
}


No you can not use multiple try with one Catch, try using multiple try's and press double tab button it will create try catch block automatically.


这篇关于多次尝试一次捕获可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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