尝试在 Siebel 中使用 Catch 块
我有一个脚本,它将一组记录发送到一个文件中。我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在大多数语言中(除非您使用非常奇怪的东西),如果“writerecord event”不抛出异常,则不会调用 catch 块。
你不是说:
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 :
您是否试图循环遍历查询返回的一些记录?做这样的事情:
Are you trying to loop through some records that are returned by a query? Do something like this:
您可以使用 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.
同意“最终”可能是最好的选择 - 但我们知道例外实际上是什么吗? - 你能否在 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?
因此,如果您未能提交此记录,您将尝试移至下一条记录。罗伯特·穆勒说得对。解释一下...
如果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.