One way of handling errors inside a plugin is to create a system where the
plugin returns an error code. Another way is to handle the errors directly
inside the plugin, but that is for another discussion.
To return an error code the plugin must be constructed to return a value. When using the Plugin Wizard create your command as you would normally do, but also add a return value of a Longint. This will add the following line of code to your plugin command:
PA_ReturnLong( params, returnValue );
During the processing of your plugin if an error is encountered you would set the returnValue with the above code. In 4D you can then trap for this value and do any data processing that may be necessary. By returning a value from a plugin you can create your own error code system such that all plugin calls follow. An example would be a plugin call that takes a 2-character string for the state abbreviation and returns the current sales tax rate. If the string passed is invalid you could return a 1 from the plugin call, if the command returns the Sales Tax correctly you can return a 0.
ErrorCode := ex_SalesTax(vs2_StateAbbr; vr_SalesTax)
:(ErrorCode = 1)
ALERT("State Abbreviation Incorrect!")
:(ErrorCode = 0)
In the future you could add more error checking inside the plugin so that
you can return different types of error codes to 4D.