MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

ESSENTIALS: Home | Tips | Search | Categories | Top 10 | Products | Authors | Blogs | Forums | Webcasts | Advertise | About
exception handling in sql server 2005 -

in Search

exception handling in sql server 2005

Last post 06-19-2008 6:28 AM by aprato. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-18-2008 3:03 PM

    exception handling in sql server 2005

    hi every body,

    i have a problem with exception handling in sql server 2005   i have written a code like


    CREATE Procedure PaginRec

        (
        @PageNum int,
        @NumOfRec int
        )
    as
       
             begin try
                      Begin
                          with DIVRES as (
                              select Row_Number() over(order by Responsible desc)
                              as row, Responsible , Division
                              from Bulist)

            select Responsible,Division
            from DIVRES
            where row between
            (@PageNum - 1) * @NumOfRec + 1 and @PageNum*@NumOfRec
           
                    end
            end try


            begin catch
            select  'Pleas enter the right num of parameters'
            end catch

     

     

    when i execute this stored procedure like this

    PaginRec                         (without passing any parameters) 

    it should give error message like 'Please enter the right num of parameters

    but it doesnt. plz cud u help me to do it in a proper way. 

    how msg shud be dispalyed if  user doesnt pass proper parameters

    thanks in adv,

    regards

    learner 

    Filed under:
  • 06-18-2008 11:31 PM In reply to

    Re: exception handling in sql server 2005

    Hi,

     Try and catch block will work if u are calling proc properly.

    If any error comes while executing the procedure then the given error message will come.

    Here you are not calling a procedure properly

     

    Thanks & Regards

    Brijendra Pandey

    Thanks & Regards
    Brijendra Kumar Pandey
  • 06-19-2008 6:28 AM In reply to

    • aprato
    • Top 10 Contributor
    • Joined on 12-01-2007
    • Greater Boston
    • Posts 190

    Re: exception handling in sql server 2005

     There's probably no SQL Server error which triggers the CATCH block to run.  

     

    Why not just check both  @PageNum  and @NumOfRec for NULLs prior to executing the SQL or set them to default values

    if they're passed in as NULL? 

Page 1 of 1 (3 items)