Home > Ask the SQL Server Experts > Joe Toscano - Integration Services/Development Questions & Answers > Problems with structured exception handling
Ask The SQL Server Expert: Questions & Answers
EMAIL THIS

Problems with structured exception handling

Joe Toscano EXPERT RESPONSE FROM: Joe Toscano

Pose a Question
Other SQL Server Categories
Meet all SQL Server Experts
Become an Expert for this site


Expert advice on database administration
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 10 October 2006
I recently read your article "Tuning stored procedures: Structured exception handling in SQL Server 2005" and I was trying to implement the concept discussed. However, it seems the control doesn't enter into the catch block. What should I do?

>
EXPERT RESPONSE
Try a much simpler example first. This example will fail because we attempt to insert a NULL value into a column that does not allow NULLs:

CREATE TABLE dbo.emp (
empno int NOT NULL)
go
create procedure  dbo.p_emp_insert
(@empno int)
as
begin
 -- CODE THAT MAY FAIL
  begin try

  insert into emp (empno)
            values (@empno)
      end try

 -- EXECUTED IF THERE IS A FAILURE
 begin catch

    SELECT ERROR_NUMBER()as ERROR_NUMBER,
    ERROR_SEVERITY()as ERROR_SEVERITY,
    ERROR_STATE()as ERROR_STATE,
    ERROR_MESSAGE()as ERROR_MESSAGE

 end catch

end

-- First exec should work with a valid empno
exec dbo.p_emp_insert 1003

-- This should fail because the column does not allow NULLs
-- We should see the error information returned
exec p_emp_insert NULL


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
Joe Toscano - Integration Services/Development
How to convert DTS packages to SSIS and overwrite data
How to migrate DTS to SSIS and deploy SSIS packages
Query to search text in old DTS packages in SQL Server?
Error importing Excel data to SSIS in SQL Server 2005
Delete .bak files automatically with CLR
DTS package designed to overwrite extract.xls
Displaying a SQL Server database report in Excel
Stored procedure practices in SQL Server
Call triggers in a stored procedure
SQL Server permission to create jobs and schedules in SSIS

SQL Server stored procedures
SQL and SQL Server Tutorial and Reference Guide
SQL Server stored procedures tutorial: Write, tune and get examples
Check SQL Server database and log file size with this stored procedure
SQL Server source code analysis and management adds database security
Configure SQL Server Service Broker for sending stored procedure data
Find size of SQL Server tables and other objects with stored procedure
Track changes to SQL Server 2000 and 2005 with one simple utility
Troubleshoot SQL Server 2005 temporary table performance problems
Use SQL Profiler to find long running stored procedures and commands
Stored procedure to monitor long-running jobs in SQL Server 2000

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
library  (SearchSQLServer.com)
trigger  (SearchSQLServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2005 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts