views:

375

answers:

7

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
}
}
A: 

Dear fellow SO'ers, this answer should be a comment.
It was posted by a new user, and has already been downvoted twice (at the time of this writing).
Give our new colleague time to get up to speed, and realise he should delete this post.

I'm asking that we refrain from down voting further, lets be nice to the noobs :)
Binary Worrier

Original post


Could you post some sample code?

pipelinecache
this is a comment not an answer.
Sam Holder
Could you ask that in a comment, not an answer. Answers are for answers, this is a question, and as a non answer is a downvote magnet (don't shoot the messenger)
Binary Worrier
That's not an answer. I suggest you delete this. We're already inundating the OP with requests for sample code in the comments.
Carl Smotricz
A: 

working on Siebel - scripting

Priya
You should provide additional information like this by editing your question, not by posting an answer.
anon
+1  A: 

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.

valli
This won't help him if he is iterating the records inside the try-catch block.
Dana
+4  A: 

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}
}
phtrivier
A: 

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?

monojohnny
A: 

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());
}
Thomas Müller
A: 

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.

Mike M. Lin