Continue the loop

Hi Everybody, It’s good to be back. I know it’s been a long break but was badly stuck. Now, You must be thinking what a strange topic header but I just couldn’t think of anything better and let’s not waste more of your precious time with pleasantries and get straight to the point.

In this post I am talking about a requirement that somebody asked me long back.

Requirement:

I have written a code to process a set of records. It includes a while loop and NextRecord function to traverse through those records and perform a set of operations on those records.

Here is a pseudo code of what I am trying to do

 
 
 

 This is usually how we write the code to process the records but in case if an error occurs in the loop then execution stops immediately and control goes to Catch and then Finally block.

Now the requirement is to process all the records irrespective of the fact an error occured or not. In other words , if an error occurs log the error and go on to process next record as usual don’t stop.

Sound’s simple enough!! How can I do that???

This is the big question that we need to answer. So, keeping up with old tradition I am leaving this question unanswered and waiting for your ideas/thoughts/answers on this. I will be answering this question on Friday Morning EST (You know where I am right now 🙂 ).

So, what are you waiting for ???

Update:

Sorry, for update in delay but have been stuck with forum problem and haven’t found anything to work yet. I don’t want to mess up the data that is why it taking longer than it should.

sukumar432, sebastian1, Thomas Müller  have given the right answer to the question.

We need to use Nested Try Catch Statements. I know it sounds simple to experienced guys but it is not as simple for person relatively new to Siebel.  Pseudo Code to accomplish has already been given in comments but I will give it here also.

try{
//getBO
//getBC
//ExecuteQuery
while(recFound) {
try{
//do something
}
catch(e){
// log error
}
//recFound = NextRecord
}
}
catch(e){
//error Occured I am out of here
}
finally{
//nullify the objects
}

 

7 Responses to Continue the loop

  1. yep, this is similiar to something i have implemented. I put the processing steps in a separate function with its own try catch loop. in this catch, we would simply log the error and not raise an exception. then the main loop called this function

  2. Hm… I'd say Thomas is right. Though I'd keep a try/catch/finally block outside the loop in case of an error during the query or NextRecord() operations:

    try{
    //getBO
    //getBC
    //ExecuteQuery
    while(recFound) {
    try{
    //do something
    }
    catch(e1){
    // log error
    }
    //recFound = NextRecord
    }
    }
    catch(e2){
    //error Occured during querying or cursor operation
    }
    finally{
    //nullify the objects
    }

    …but the again, neel wouldn't post this question if it was that simple…

  3. We have Implemented the same using the following Pseduo code similar to above one using two catch statements

    try{
    //getBO
    //getBC
    //ExecuteQuery
    while(recFound) {
    //do something
    try
    {
    // Update something
    WriteRecord
    }
    catch(e)
    {
    TheApplication().RaiseErrorText(e);
    }
    //recFound = NextRecord
    }
    }
    catch(e){
    //error Occured I am out of here
    }
    finally{
    //nullify the objects
    }

  4. We had similar issue, before reading this post we got resolved using same functionality. If i might have seen this, i may saved some more time rather than breaking my head 🙂 !!
    U PEOPLE REALLY ROCKS!!

  5. In my wf i have connected all error handlers to Error handling subprocess to log erros and connected it to the end step..but even if it errors out fr any in between records i just want to log the error and continue to next record..How this can be achieved through workflows..Somebody pls provide your inputs..

Leave a Reply

Contribute