如何抛出异常到下一个捕获? [英] How to throw exception to next catch?

查看:85
本文介绍了如何抛出异常到下一个捕获?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在下一个捕获时抛出异常,(我附有图片)

I want to throw an exception at next catch, (I attached image)

有人知道该怎么做吗?

推荐答案

您不能这样做,这表明您在catch块中逻辑太多,或者应该重构方法只做一件事情.如果无法重新设计,则必须嵌套try块:

You can't, and trying to do so suggests that you've got too much logic in your catch blocks, or that you should refactor your method to only do one thing. If you can't redesign it, you'll have to nest your try blocks:

try
{
    try
    {
        ...
    }
    catch (Advantage.Data.Provider.AdsException)
    {
        if (...)
        {
            throw; // Throws to the *containing* catch block
        }
    }
}
catch (Exception e)
{
    ...
}

这篇关于如何抛出异常到下一个捕获?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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