Ignoring an exception

Can’t seem to get my code to ignore an exception. I understand that this is generally not good practice, but in this case we have some records stuck in our IntQueIn table that shouldn’t be there. Proof is that some records do not show up in the Integrated Table Workbench. I’m trying to develop a solution that sends email to different areas of the business so they can correct these rather than IT. (IT should make the change, after the business advises what went wrong)

When I call the method ProcessIntQueIn i can’t seem to ignore the exception that is raised from it. Generic try catch, catch with the specific exception, or anything. I want my code to continue to add the error messages to my grid regardless if the method fails.

private void ebtGetErrors_Click(object sender, System.EventArgs args)
{
	// ** Place Event Handling Code Here **

	IntgWorkbenchAdapter ma = new IntgWorkbenchAdapter(oTrans);

	ma.BOConnect();

	for (int i = 0; i < eugData.Rows.Count; i++)
	{
		try
		{
			if (eugData.Rows[i].Cells["IntQueIn_IntError"].Value.ToString() == "True")
			{

				ma.ProcessIntQueIn(Int32.Parse(eugData.Rows[i].Cells["IntQueIn_IntQueID"].Value.ToString()), eugData.Rows[i].Cells["IntQueIn_RelatedToFile"].Value.ToString(), eugData.Rows[i].Cells["IntQueIn_ExtSystemID"].Value.ToString(), true, false);

				eugData.Rows[i].Cells["Error"].Value = ma.GenericIMDataSet.IntgValidationError.Rows[i]["ErrorMessage"].ToString();

			}
			eugData.Refresh();
		}
		catch (Exception)
		{ 
			//do nothing
		}
	}
		
	ma.Dispose();

}

Error I receive using the bl tester

TargetInvocationException

Inner Exception:
Object reference not set to an instance of an object.
at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)
at Erp.Proxy.BO.IntgWorkbenchImpl.GetIMRecord(String ipRelatedToFile, Int32 pIntQueID, Guid gSysRowID, GenericIMDataSet ttGenericIMTablesetDS)

The exception is probably being thrown outside of the stack, so you can’t catch it that way. Can you clear out the bad records, or work with Epicor to fix that? Suppressing a true exception is like you said, a very bad idea

I think your eugData is null. based on the exception. either way good idea to put a eugData.Rows > -1 check in there or somet null checks.

EDIT: There are a lot of good records in this table that can be viewed in the Integration Table Workbench, and is the primary reason i’m trying to do this. We plan to work with Epicor to resolve the “bad records” however want the code to continue executing to aggregate the error messages for the good records.

When I implement the Try Catch block the message no longer appears, but stops the code. tried putting a continue/break in there and nothing different.

Agreed i should. However it runs for 46 records, then stops once it gets an exception from the BO

Is BC you are using the adapter and the adapter is handling the exception for you
Switch to using the raw BO

The exception is thrown by the BO and caught and “handled” by the adapter which chooses to display the message and abort

1 Like

When you say switch to using the raw BO, do you mean the below? Still seem to be encountering the same issue.

IntgWorkbenchImpl ma = WCFServiceSupport.CreateImpl<Erp.Proxy.BO.IntgWorkbenchImpl>(FormFunctions.getILaunchSession(oTrans), Erp.Proxy.BO.IntgWorkbenchImpl.UriPath);

Yeah that, kind of you should be able to catch the exception if its coming from the BO. Since there’s nothing catching it

What is throwing the error?

Figured this one out. Turns out that when i would catch the exception, it would just appear that my code was being killed. In actuality I kept referencing a row that didn’t exist YET for each row in eugData.

In my original code i check the boolean value “IntQueIn_IntError” to see if I should call the BO to pull the error message in. There is one record currently in my IntQueIn table that is false. When i would skip calling the BO, the below line would be out of sync between eugData.DataSource and the GenericIMDataSet.

eugData.Rows[i].Cells["Error"].Value = ma.GenericIMDataSet.IntgValidationError.Rows[i]["ErrorMessage"].ToString();

I fixed it by referencing a different int x, and incremented it everytime I call the function

int x =0;

for (int i = 0; i < eugData.Rows.Count; i++)
{
	if (eugData.Rows[i].Cells["IntQueIn_IntError"].Value.ToString() == "True")
	{
		string cErrMsgs;
		ma.ProcessIntQueIn(Int32.Parse(eugData.Rows[i].Cells["IntQueIn_IntQueID"].Value.ToString()), eugData.Rows[i].Cells["IntQueIn_RelatedToFile"].Value.ToString(), eugData.Rows[i].Cells["IntQueIn_ExtSystemID"].Value.ToString(), true, false, out cErrMsgs, im);
		if (im.IntgValidationError.Rows[x]["ErrorMessage"].ToString() != "")
		{
			eugData.Rows[i].Cells["Error"].Value = im.IntgValidationError.Rows[x]["ErrorMessage"].ToString();
		}
		
		x++;
	}
	eugData.Refresh();

}

Thank you everyone for your suggestions and help. I now know how to call BO’s without adapters which is cool. :nerd_face:

1 Like

For reference it was an IndexOutOfRangeException, which should have made it obvious. I kept my laser sights on the record I skipped which would have thrown and error, even though I never called the BO for that row in my code.