简体   繁体   中英

customize an error message in SQL server 2008 R2 on win 7

I need to customize an error message in SQL server 2008 R2 (no support for throw) on win 7.

  BEGIN TRY
   DECLARE @result INT
   SET @result = LOG(-1)
  END TRY

 BEGIN CATCH
  EXEC sys.sp_addmessage 60000, 16, 'log() argument is not positive'
  RAISERROR (60000, 16, 1)
 END CATCH

But, the result is always the same :

An invalid floating point operation occurred.

Thanks

You can get around this by using a variable for the Log argument:

DECLARE @result INT
DECLARE @insidelog INT = -1
IF @insidelog < 0
    BEGIN
        EXEC sys.sp_addmessage 60000, 16, 'log() argument is not positive'
        RAISERROR (60000, 16, 1)
    END
ELSE
    BEGIN
        SET @result = LOG(@insidelog)
    END

I assume you'd be passing that number as a variable anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM