Throw new Ice.BLException

What is the expected result from using the following in UI customisation?

    throw new Ice.BLException

I was expecting that any subsequent code would not be called. This appears to be true within the method/block that I use it, but it still returns back to a calling method and continues executing code. If I try to put a return; statement in after the exception call, the editor says it’s unreachable code!

What are you trying to accomplish? Are you hijacking that for your own custom error handling?

Yes I am.

lPass = adapterReportQty.OnChangeJobNum(jobNum);
if(!lPass)
{
	lContinue = false;
	throw new Ice.BLException("Error occured in ReportQty.OnChangeJobNum method");
}	

I used it because I saw it on here somewhere, and it gives an Epicor formatted error box with the icon etc. I also thought because it was using EpiMagic it would roll back transaction etc, where a MessageBox.Show would be more basic.

Am I wrong to use it in this scenario? Is there a better way?

well…im not saying there is, but probably. There are far more experienced programmers on here than me but one axiom i typically stick with is don’t hijack. Let Epicor take care of the business logic side of things. When it gets violated just let it handle itself, or depending on what you are trying to accomplish catch it through other means. Usings are good, as well as Try/Catch/Finally statements. There has only been one time ever i can recall truly needing my own custom error handling and I think i wasn’t invoking any Epicor logic around it. Most of the time you can guide program flow and logic through other best practice means. You’re far better to validate incoming data if you expect errors or that it may be unreliable in the first place. Maybe post your code in it’s entirety and a pile of us could offer suggestions?

The BLException is ok to use but if what you are trying to do is halt processing try throwing a
throw new Exception (“bad stuff”)
Now you said this was the UI so that should cause an error which will stop excecution and fall through until something catches that error.

As @rbucek suggests you should catch this exception and handle it somehow.

Can you show us the calling tree of where this call is made?
Give us a bit more context

Oh OK - the whole customisation is 2500 lines long, and does lots of other things.

Are you saying that I need to catch this Exception? Is that using a try/catch block? If that is the case, what might be happening is that it’s showing these errors when it gets back to the calling method.

Let me try and pick out the relevants part of the code…

private void cmbProcess_Click(object sender, System.EventArgs args)
{
	if(nQtyReported > 0)
	{
		throw new Ice.BLException("Qty already reported against this job.  Create another job if required to report further qty");
	}

	string failMsg = String.Empty;
	bool lContinue = ValidateRequiredInputs(out failMsg);
	if(!lContinue)
	{
		throw new Ice.BLException("One or more inputs missing! " + failMsg);
	}

	// Check that appropriate materials issued
	if(!AllMaterialsIssuedCheck())
	{
		MessageBox.Show("Check Issued Materials - either 10% under issued or 10% over issued"); 
		return;
	}
			
	bool lQAHold = chkQAHold.Checked;
	string sJobNo = txtJobNo.Text;
	string sPartNo = txtPartNo.Text;
	string sLotNo = String.Empty;
	string sEmpNo = txtEmpID.Text;
	string sSerialNo = txtPalleconSerial.Text;
	string sSampleID = txtSampleID.Text;
	int iShelfLifeDays = GetPartShelfLifeDays(sPartNo);
	int nQty = Convert.ToInt16(numQty.Value);
	DateTime dExp = Convert.ToDateTime(dteExpDate.Value);
	DateTime dJobDate = Convert.ToDateTime(dteJobDate.Value);
							
	// Ensure Expiry Date is within accepted parameters		
	lContinue = ValidExpiryDate(Convert.ToInt16(numShelfLifeDelta.Value), sPartNo);
	if(!lContinue)
	{
		return;
	}

	// Check Qty Reported is within tolerance
	lContinue = QtyWithinTolerance(sPartNo);
	if(!lContinue)
	{
		return;
	}

	// Perform ReportQty Method
	ReportQty(sEmpNo, sJobNo, nQty, out lContinue);
	if(!lContinue)
	{
		throw new Ice.BLException("Error occured during ReportQty method, aborting");
	}
		
	// Check if Lot Tracked, if so then Create Lot Number
   	if(GetPartLotTrackedStatus(sPartNo))
	{
		sLotNo = CreateLot(sJobNo, sPartNo, iShelfLifeDays, dJobDate, dExp, lQAHold, sSerialNo, out lContinue);
		if(!lContinue)
		{
			throw new Ice.BLException("Error occured during CreateLot method, aborting");
		}
	}
		
	// Perform JobReceiptToInventory
	JobReceiptToInventory(sJobNo, sPartNo, sLotNo, dJobDate, out lContinue);
	if(!lContinue)
	{
		throw new Ice.BLException("Error occured during JobReceiptToInventory method, aborting");
	}

	// Close Job once reported
	CompleteCloseJob(sJobNo);

	// Put Lot on QA Hold if required
	if(lQAHold)
	{
		PutLotOnHold(sPartNo, sLotNo);
	}
		
	MessageBox.Show("Complete - Received to Inventory using Lot Number " + sLotNo);
	refreshDashboard();
	ClearScreenFields();
							
}

Reason I’m pouring back over it is because I had a report earlier that a user couldn’t “process” a job. When I looked, the Job was Closed. It also had Qty reported against it.

So basically I think that an error must have occurred within the method call:

JobReceiptToInventory(sJobNo, sPartNo, sLotNo, dJobDate, out lContinue);

But, rather than error out it continued on and called:

CompleteCloseJob(sJobNo);

I wasn’t expecting that after the throw new Ice.BLException…