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
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.
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);
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.
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.