如何从脚本任务中调用的自定义类库中捕获异常?

时间:2012-11-06 14:48:55

标签: vb.net ssis

我在VB.NET中创建了一个类库,我们从SSIS脚本任务调用它。

有人可以建议我如何从VB.NET函数中抛出错误,假设返回一个字符串值,但它返回null,在这种情况下我希望SSIS脚本任务失败。

1 个答案:

答案 0 :(得分:1)

如果从函数库中抛出任何异常/ Null,则可以使用以下代码使包失败。将YourMethodCall()替换为您的方法。

C#:

// For General exceptions
try
{
    // Your Method call
    var x = YourMethodCall();

    if (string.IsNullOrEmpty(x))
    {
        Dts.Events.FireError(0, "Your component Name", "Your Error Message", string.Empty, 0);
    }
    else
    {
        bool isFireAgain = false;
        Dts.Events.FireInformation(0, "You component Name", "Your Information for Successful run", string.Empty, 0, ref isFireAgain);
    }
}
catch (Exception ex)
{
    Dts.Events.FireError(0, "Your component Name", String.Format("Failed and Exception is : [{0}]",ex.Message), string.Empty, 0);
}

希望这有帮助!

相关问题