473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Exception Handling in DB2 UDB

Hi,

Could any one tell that, how to handle the exceptions mainly after the
insert statement.

I am writing a PL SQL Procedure, it must capture the exception if any.
Also I need the error description for that errror.

Regards,
Ravi.

Mar 7 '06 #1
3 10209
Hi,

Even I was trying to catch exceptions and this is what i was trying.
Hope others will chip in with some more EFFECTIVE examples::

CREATE PROCEDURE test ( IN cntry_cde CHAR(2))
SPECIFIC test
LANGUAGE SQL

se: BEGIN

-- Declare return codes

DECLARE ERRORFLAG INTEGER DEFAULT 0;
DECLARE insert_error CONDITION FOR SQLSTATE 'put the error code here';
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE SQLCODE INT DEFAULT 0;

DECLARE CONTINUE HANDLER FOR insert_error
BEGIN
SET errorflag = 1;
END;

-- LOGIC

INSERT into test.t_emp VALUES('1,'tariq','IBM DB2 UDB');

IF ERRORFLAG=1 THEN
-- DO SOME THING
END IF;

END se
regards,
tariq

Mar 7 '06 #2
http://www.db2click.com/my_script_di...orHandler.html

shows one approach to handle exception and continue circumstances

HTH

Sathyaram

Mar 7 '06 #3
rAinDeEr wrote:
Hi,

Even I was trying to catch exceptions and this is what i was trying.
Hope others will chip in with some more EFFECTIVE examples::

CREATE PROCEDURE test ( IN cntry_cde CHAR(2))
SPECIFIC test
LANGUAGE SQL

se: BEGIN

-- Declare return codes

DECLARE ERRORFLAG INTEGER DEFAULT 0;
DECLARE insert_error CONDITION FOR SQLSTATE 'put the error code here';
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE SQLCODE INT DEFAULT 0;

DECLARE CONTINUE HANDLER FOR insert_error
BEGIN
SET errorflag = 1;
END;

-- LOGIC

INSERT into test.t_emp VALUES('1,'tariq','IBM DB2 UDB');

IF ERRORFLAG=1 THEN
-- DO SOME THING
END IF;

END se

Tariq,

Why don't you "do something" inside the handler iteslef (that's why it's
called a handler :-)

also note that handlers can (and typically should be specific to teh
statement:
BEGIN
DECLARE .. HANDLER FOR SQLSTATE ....
BEGIN
-- do something
END
INSERT ....
END

It's like Java try... catch
Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: adi | last post by:
Dear all, This is more like a theoretical or conceptual question: which is better, using exception or return code for a .NET component? I had created a COM object (using VB6), which uses...
6
by: Daniel Wilson | last post by:
I am having exception-handling and stability problems with .NET. I will have a block of managed code inside try...catch and will still get a generic ..NET exception box that will tell me which...
7
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
3
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech...
2
by: tom | last post by:
Hi, I am developing a WinForm application and I am looking for a guide on where to place Exception Handling. My application is designed into three tiers UI, Business Objects, and Data Access...
9
by: C# Learner | last post by:
Some time ago, I remember reading a discussion about the strengths and weaknesses of exception handling. One of the weaknesses that was put forward was that exception handling is inefficient (in...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
4
by: Ele | last post by:
When Exception handling disabled compiler still spits out "C++ exception handler used." Why is that? Why does it ask for "Specify /EHsc"? Thanks! c:\Program Files\Microsoft Visual Studio...
41
by: Zytan | last post by:
Ok something simple like int.Parse(string) can throw these exceptions: ArgumentNullException, FormatException, OverflowException I don't want my program to just crash on an exception, so I must...
1
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.