简体   繁体   中英

How to throw exception in epicor C#

What is the equivalent to &THROW_PUBLIC in C# or what does &THROW_PUBLIC mean is ABL? I don't know much about ABL but need to convert it to C#.

Code Snip from a Data Directive in Epicor 9.05

If ttPart.ProdCode = '' then do:

   If lookup(SUBSTRING(ttPart.PartNum,1,3),'12-,13-,14-,15-',',') <> 0 then do:

    {lib\PublishEx.i &ExMsg = "'Please select a Product Group for this Part'"}
    {&THROW_PUBLIC}.

   End.

End.

&THROW_PUBLIC is not a Progress ABL keyword or any standard feature at all. Most likely it's something specific to Epicor.

For better understanding of the problem perhaps you should post more code!

However: beginning with an ampersand might be a clue to it being a preprocessor. A preprocessor can be defined with GLOBAL-DEFINE or SCOPED-DEFINE - look for that in your code.

When the program is compiled any reference to the preprocessor (written like {&name-of-preprocesor} will be replaced with it's definition. Certain limited checks can be done (like for instance what OS is used for compiling).

Here's an example of two preprocessors being defined and used.

&GLOBAL-DEFINE THROW_PUBLIC1 MESSAGE "HELLO 1".
&SCOPED-DEFINE THROW_PUBLIC2 MESSAGE "HELLO 2".

{&THROW_PUBLIC1}
{&THROW_PUBLIC2}

After the precompiler the program will simply look like this:

MESSAGE "HELLO 1".
MESSAGE "HELLO 2".

The THROW part might indicate some kind of error handling being used like a THROW-CATCH -situation or similar. They are written something like this:

BLOCK-LEVEL ON ERROR UNDO, THROW. 

DEFINE VARIABLE i AS INTEGER     NO-UNDO.
ASSIGN 
    i = INTEGER("hello").

CATCH err AS Progress.Lang.Error:
    MESSAGE "Error is caught here" VIEW-AS ALERT-BOX.
END.

FINALLY:
    MESSAGE "This is run in the end" VIEW-AS ALERT-BOX.
END.

{&THROW_PUBLIC}. is defined in the Epicor include file manager\\Exception.i (this is probably xcoded so you can't read it). This basically skips to the end of the {&TRY_PUBLIC} / {&CATCH_PUBLIC} block and publishes an exception.

In c# it is much easier:

throw new Ice.BLException("Please select a Product Group for this Part");

You can use a standard System.Exception but Ice.BLException (defined in Epicor.ServiceModel.dll) has some overloads to record extra information which other parts of the framework can display/log.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM