Try catch block with continue

Hi,

I am little new to WM and trying to develop few services. I have a for loop in which i am calling JDBC adapter service which inserts the record in DB but if there is anything wrong in insert statement then the whole service boms out instead i want to use try catch block along with continue statement. I mean if there is any exception it should keep inserting remaing records.

Please help me to understand how best i can do this.

Thanks
Atul

Hi Atul,

This will work the way you want :

1.main sequence
1.1 try sequence
1.1.1 loop
1.1.1.1 main sequence
1.1.1.1.1 try sequence
1.1.1.1.1.1 jdbc service
1.1.1.1.1 catch sequence
1.1 catch sequence

Basically what you have to do is have try-catch block (child) inside a try-catch block (parent) and the loop should on try-catch block (child).

Hope you get what I want to say.

Regards,
Sumit

Hi Sumit,

Thanks for the reply. I will try our your solution today. One thing which i want to ask here is will it insert remaining records in DB if there is any exception in JDBC service for say any record?

The reason i am asking you this is i don’t see any continue statement in this praposed solution.

Thanks
Atul

Hi Atul,

There is no continue statement in flow.
What you want to do is in case of any exception in loop, catch it in (child) catch block but do not roll back or throw exception, in this case it will continue to next record.

In case of any exception outside your loop, it will be caught in final (parent) catch block, there you can roll back transaction and commit in the last step of your (parent) try block.

Regards,
Sumit

Hi Sumit,

I tried your suggestion. Have alook of attached file. But still if any records fails the whole service boms out.

Please suggest.
Trycatch-block.GIF

Hi Atul,

2 things :

  1. You have not implemented parent try-catch block (its anyway optional)
  2. In child try-catch block, all the flow steps should be inside "Try Block Exit On Failure"i.e. MAP, GetNextUniqueKeyID etc… should be inside try block.

Also did u set “Main for Loop Sequence” block as “Exit on Success” ?

Regards,
Sumit

Hey Sumit, u r gr8 man. It is working now the way i wanted.

Thanks, Appreciated.

Atul