0

I have seen similar questions regarding this topic which were asked earlier but couldn't find a solution for the above problem. I have an add-on programmed in c# for SAP B1. User has to enter some database column names to a UDT. Then my function run a query and fetch the data. But in case of user entering wrong column name to the table, I should have a proper error handling to catch this error and prevent the add-on from crashing. My code is given below.

try
{
 sqlString = "select " + databaseFieldName[increase] + " from OITM where ItemCode= '" + itemCode + "'";
 mRsitemCode.DoQuery(sqlString);
}
catch (System.Runtime.InteropServices.COMException ex)
{
 SBO_Application.MessageBox(ex.ToString(), 1, "Ok");
}
catch (Exception b)
{
  //string error;
  SBO_Application.MessageBox(b.ToString(), 1, "Ok");
}

But it doesn't run into any of my catch blocks. The error is given below.

An exception (first chance) of type 'System.Runtime.InteropServices.COMException' occurred in Item_Variation.dll.

Additional information: 1). [Microsoft] [SQL Server Native Client 10.0] [SQL Server] Invalid column name 'WhsCode'.

2). [Microsoft] [SQL Server Native Client 10.0] [SQL Server] Statement (s) Could not be prepared.

If a handler is available for this exception, the program may continue to run safely.

What am I doing wrong? Any help would be highly appreciated!

7
  • Are you sure that: 1. the exception actually occurs in the shown line and not somewhere else? 2. the line in exception handler isn't actually being executed? Maybe simply the message box is not shown? Can you stop in the line with the debugger? Commented Jan 26, 2016 at 13:08
  • @KubaWyrostek : I tried to debug and it stoped at line mRsitemCode.DoQuery(sqlString); and the error messaged popped up(crashed). It didn't run into the catch block. Commented Jan 26, 2016 at 13:11
  • Do you have your settings configured to break on exceptions. I am not sure this is the cause of the problem, but might be something Commented Jan 26, 2016 at 13:12
  • @ChrisBint No Idea. How can I do it VS2010? Forgive me I'm just an intern :( Commented Jan 26, 2016 at 13:13
  • From Debug/Exceptions menu. You can simply select it not to break on any exception, but again, not sure if this is your problem or not. Might be worth trying. Commented Jan 26, 2016 at 13:15

1 Answer 1

1

Your Visual Studio is configured to break on exceptions. If you use the Debug/Exceptions menu to select which errors you would like to break on, rather than let your code continue, you can do so.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.