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!
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…
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…