尝试在 Siebel 中使用 Catch 块

发布于 2024-08-14 08:27:14 字数 230 浏览 7 评论 0原文

我有一个脚本,它将一组记录发送到一个文件中。我正在使用 Try - Catch 块来处理异常。在 catch 块中,我有一个代码,其中包含指向下一条记录的指针。但这并没有执行。基本上我想跳过坏记录并移动到下一条记录。

while(currentrecord)
{
try
{
writerecord event
}
catch
{
currentrecord = next record
}
}

I have a script which sends a set of records into a file. I'm using Try - Catch block to handle the exceptions. In the catch block I have a code where it has the pointer to next record. But this is not executing . Basically I wan to skip the bad record n move to next record.

while(currentrecord)
{
try
{
writerecord event
}
catch
{
currentrecord = next record
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

音盲 2024-08-21 08:27:14

在大多数语言中(除非您使用非常奇怪的东西),如果“writerecord event”不抛出异常,则不会调用 catch 块。

你不是说:

while(currentrecord) { 
   try { writerecord event } 
   catch { log error } 
   finally { currentrecord = next record}
}

In most languages (unless you're using something very strange), If 'writerecord event' doesn't throw an exception, the catch block will not be called.

Don't you mean :

while(currentrecord) { 
   try { writerecord event } 
   catch { log error } 
   finally { currentrecord = next record}
}
脸赞 2024-08-21 08:27:14

您是否试图循环遍历查询返回的一些记录?做这样的事情:

var yourBusObject = TheApplication().GetBusObject("Your Business Object Name");
var yourBusComp = yourBusObject.GetBusComp("Your Business Component Name");

// activate fields that you need to access or update here
yourBusComp.ClearToQuery();
// set search specs here
yourBusComp.ExecuteQuery(ForwardOnly);

if (yourBusComp.FirstRecord()) {
    do {
        try {
            // update the fields here
            yourBusComp.WriteRecord();
        } catch (e) {
            // undo any changes so we can go to the next record
            // If you don't do this I believe NextRecord() will implicitly save and trigger the exception again.
            yourBusComp.UndoRecord();

            // maybe log the error here, or just ignore it
        }
    } while (yourBusComp.NextRecord());
}

Are you trying to loop through some records that are returned by a query? Do something like this:

var yourBusObject = TheApplication().GetBusObject("Your Business Object Name");
var yourBusComp = yourBusObject.GetBusComp("Your Business Component Name");

// activate fields that you need to access or update here
yourBusComp.ClearToQuery();
// set search specs here
yourBusComp.ExecuteQuery(ForwardOnly);

if (yourBusComp.FirstRecord()) {
    do {
        try {
            // update the fields here
            yourBusComp.WriteRecord();
        } catch (e) {
            // undo any changes so we can go to the next record
            // If you don't do this I believe NextRecord() will implicitly save and trigger the exception again.
            yourBusComp.UndoRecord();

            // maybe log the error here, or just ignore it
        }
    } while (yourBusComp.NextRecord());
}
笑着哭最痛 2024-08-21 08:27:14

您可以使用 try-finally 结构,以便无论代码是否抛出异常,finally 块内的任何内容都将始终被执行。它通常用于清理资源,例如关闭文件或连接。如果没有 catch 子句,try 块中抛出的任何异常都将中止执行,跳转到 finally 块并运行该代码。

You can use try-finally structure so that whatever inside the finally block will always be executed, regardless of whether the code throws an exception or not. It's often used to clean up resources such as closing files or connections. Without a catch clause, any thrown exception in your try block will abort execution, jump to your finally block and run that code.

倾城泪 2024-08-21 08:27:14

同意“最终”可能是最好的选择 - 但我们知道例外实际上是什么吗? - 你能否在 catch 循环中输出它,以便:

A)你可以证明正在抛出异常(而不是说返回“null”或其他内容)

B)确保你得到的异常不是可能的异常阻止“nextrecord”也工作...[不确定“最后”在这种情况下会实现什么 - 大概异常必须冒泡到调用代码?

Agree that 'finally' might be the best bet here - but do we know what the exception actually is ? - can you output it in your catch loop, so that :

A) you can prove an exception is being thrown (rather than say a 'null' being returned or something)

B) Make sure the exception you get isn't something that could prevent 'nextrecord' working as well...[not sure what the 'finally' would achieve in the case - presumably the exception would have to bubble up to calling code?

嘴硬脾气大 2024-08-21 08:27:14

因此,如果您未能提交此记录,您将尝试移至下一条记录。罗伯特·穆勒说得对。解释一下...

如果WriteRecord失败,那么业务组件仍然会定位在脏记录上。尝试移动到下一条记录将使总线补偿尝试再次写入它——因为有一个称为“隐式保存”的功能。

解决方案:您必须撤消记录 (UndoRecord) 以放弃失败的字段更改,然后再进行下一个记录。

So you're trying to move onto the next record if you failed to commit this one. Robert Muller had it right. To explain...

If the WriteRecord fails, then the business component will still be positioned on the dirty record. Attempting to move to the next record will make the buscomp try to write it again--because of a feature called "implicit saving".

Solution: You'll have to undo the record (UndoRecord) to abandon your failing field changes before moving onto the next one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文