KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Returning error codes for a Plugin
PRODUCT: 4D | VERSION: 6.7 | PLATFORM: Mac & Win
Published On: June 29, 2001
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

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)

Case of
 :(ErrorCode = 1)
  ALERT("State Abbreviation Incorrect!")
 :(ErrorCode = 0)
  `Do nothing
End case

In the future you could add more error checking inside the plugin so that
you can return different types of error codes to 4D.

http://www.4D.com/SDK