Article View: borland.public.cppbuilder.database.ado
Article #2157How do I trap the exception
From: Cherie Jo Patenaude
Date: Mon, 27 Oct 2003 23:58
Date: Mon, 27 Oct 2003 23:58
25 lines
2022 bytes
2022 bytes
I'm using BCB 6.0 enterprise with TADOQuery to talk to a SQL Server
database. I have added constraints on my tables to not allow duplicate
entries into some of the tables. I have added a try ... exception clause
around the update to trap the error, but I'm not getting the exception.
Instead there is a message box from the inside the borland code with a
fairly ugly message --
"Project CritLabel.exe raised exception class EOleException with message
"Violation of UNIQUE KEY constraint "IX_Reflectors'. Canot insert
duplicate key in object "Reflectors". Process stopped. Use Step or Run
to continue."
and it bounces me out of the save routine. I would prefer to trap the
error myself, put out a more meaningful message and roll back the update
in a more controlled manner. Do I have to set some sort of a flag or
include some special code for the compiler to handle exceptions?
The code I've used to test:
try {
RQuery->UpdateBatch(arAll);
} catch (Exception &e ) {
ShowMessage( "Exception found - "+e.message);
CSDatabase->RollbackTrans();
return;
}
Technical Details
Message-ID:
<3F9DB12E.B1D3C42F@llnl.gov>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,8b125012df64bbe2,start X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-10-27 16:09:24 PST Message-ID: <3F9DB12E.B1D3C42F@llnl.gov> Date: Mon, 27 Oct 2003 15:58:38 -0800 From: Cherie Jo Patenaude <patenaude1@llnl.gov> Organization: LLNL X-Mailer: Mozilla 4.78 [en] (Windows NT 5.0; U) X-Accept-Language: en,pdf MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.database.ado Subject: How do I trap the exception Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 128.115.26.8 X-Trace: newsgroups.borland.com 1067299118 128.115.26.8 (27 Oct 2003 15:58:38 -0700) Lines: 26 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail