# How to do Error Handling in DB2 Stored Proc?

**URL:** <https://forums.toadworld.com/t/how-to-do-error-handling-in-db2-stored-proc/40604>\
**Category:** Toad for IBM DB2\
**Created:** [February 18, 2018, 8:36pm UTC](https://forums.toadworld.com/t/how-to-do-error-handling-in-db2-stored-proc/40604 "2018-02-18T20:36:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DynoDb2](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@DynoDb2](https://forums.toadworld.com/u/DynoDb2)\
**Post date:** [February 18, 2018, 8:36pm UTC](https://forums.toadworld.com/t/how-to-do-error-handling-in-db2-stored-proc/40604/1 "2018-02-18T20:36:59Z")

</div>

Hi All,

I am very new to DB2 world and I would like to know the Implementation of Error Handling in DB2 stored procedures along with rollback.

Example Scenario: A db2 stored proc have different dml commands like Insert and updates. During the time of inserts and updates I need to implement error handling. Also if there is a dependency between Inserts and updates. If all the inserts got successful and something in the updates failed with in single stored procedure then all the inserts must rollback and should display the error message.

Thanks!!!

Waiting for the reply…

---

<div class="post-metadata">

**Author:** ![Ondrej.Zizka](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/ondrej.zizka/32/314_2.png) [@Ondrej.Zizka](https://forums.toadworld.com/u/Ondrej.Zizka)\
**Post date:** [February 19, 2018, 5:00am UTC](https://forums.toadworld.com/t/how-to-do-error-handling-in-db2-stored-proc/40604/2 "2018-02-19T05:00:08Z")

</div>

Hello DynoDb2,

Please see our Toad World Db2 Wiki. You can find there a lot of information about Db2 SP development.  
[https://www.toadworld.com/platforms/ibmdb2/w/wiki](https://www.toadworld.com/platforms/ibmdb2/w/wiki)

About error handling you can read here:  
[https://www.toadworld.com/platforms/ibmdb2/w/wiki/7756.sql-error-handling](https://www.toadworld.com/platforms/ibmdb2/w/wiki/7756.sql-error-handling)

I would recommend you use a single transaction for each bunch of commands which needs to be done all or none.

Regards  
Ondrej
