Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7789457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:18:16+00:00 2026-06-01T21:18:16+00:00

Please see the following t-sql code DECLARE @iError INT EXEC(‘select * from sysobj’) SELECT

  • 0

Please see the following t-sql code

   DECLARE @iError INT
   EXEC('select * from sysobj')
   SELECT @iError = @@ERROR
   PRINT 'Error = ' + CAST(@iError AS VARCHAR(10))

After I run it, it returns error message, which is what I want.

Msg 208, Level 16, State 1, Line 1
Invalid object name ‘sysobj’.
Error = 208

However, if I change the query

   DECLARE @iError INT
   EXEC('select * from sysobjects where ''c'' = 1')
   SELECT @iError = @@ERROR
   PRINT 'Error = ' + CAST(@iError AS VARCHAR(10))

The output will be

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value ‘c’ to data type int.

The problem is any code afer EXEC() is not executed.

In the real stored procedure, I have some code to handle the errors after PRINT. And none of those code executed in second case.

Could someone let me know why this happens?

I tested it on both SQL Server 2008 and 2005.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:18:19+00:00Added an answer on June 1, 2026 at 9:18 pm

    Different errors will have different levels of abort and some of these can be controlled through the use of settings, like ARITHIGNORE and ANSI_WARNINGS.

    I suggest reading the following article that explains all of this in great detail.

    http://www.sommarskog.se/error-handling-I.html#whathappens

    Statement-termination and Batch-abortion

    These two groups comprise regular run-time errors, such as duplicates in unique
    indexes, running out of disk space etc. As I have already have discussed, which
    error that causes which action is not always easy to predict beforehand. This
    table lists some common errors, and whether they abort the current
    statement or the entire batch.

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see following methods. public static ProductsCollection GetDummyData(int? customerId, int? supplierId) { try {
Please see the following code: List list = Collections.synchronizedList(new ArrayList()); // ... synchronized (list)
How do we update a textbox on ticking checkboxes? Please see the following code,
Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i
Please see the following code: <body> <form id=form1 runat=server> <div> <button id=helloButton> Search</button> <div
Please see the following code: #include <iostream> #include <string> using namespace std; enum dataType
I am not that familiar with PyGTK. Please see the following code. Is it
folks please see following code : #include <gio/gio.h> #include <sys/socket.h> //socket(); #include <netinet/in.h> //sockaddr_in
Please see following code I want to know how can I de-alloc cell .
Please see the following block of code import java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.