Return the error occurred in the last call of any of the plug-in functions.

Usage#Back to top


Arguments#Back to top

The function takes no arguments; note that this means it must be called without parentheses.

Result and side effects#Back to top

The function returns a string that describes the error in the last called PyFM function. If the function didn't result in an error, the result will be empty. The PyLastError itself doesn't change the last error state and can be called as often as necessary. It is safe to put it onto the ‘Watch’ tab in FileMaker Pro Advanced Data Viewer.

Examples#Back to top


This may return plugin.TrialIsOverError: The trial period of service PyRun (#2) is over. if the last function you called was PyRun() and its trial period was over. If the trial period was not over and there was no other error, it will return an empty string. If the trial period was over, but you then called another PyFM function, such as PyFM, and it didn't return an error, the string will also be empty.

Discussion#Back to top

Since the PyFM plug-in is powered by Python, all errors are Python exceptions. Python exceptions have class and value. The value is normally a string. But not always; for example, the value of SyntaxError is a more complex structure that also indicate the position of the error. Also, there's quite a few exeptions that don't have a value.)

The PyLastError function returns a single string that combines the class and the value:

<class>: <value>


ImportError: No module named 'mymodule'

If the exception is one of built-in Python exceptions, the function returns only the class name; if not, it prepends the name of the module, e.g. plugin.TrialIsOverError. If the error happened in FileMaker, the prefix will be filemaker.

How the plug-in returns errors#Back to top

The plug-in follows the FileMaker way and returns the ? string on error. Unfortunately, there's no way to distinguish this error indicator from a plain string that contains a single question mark character, so the proper way to check if there's an error is that:

  • Check if the result is a single question mark, ?.

  • If no, there's no error; if yes, call PyLastError and see if it returns a value.

  • If no, i.e. if the value is not empty, then there is no error and the question mark is the correct result. But if PyLastError returned a string, then the question mark is an indicator of an error.

To simplify this I'd recommend to use a custom function that wraps all these checks into a single call.

Another way would be to return the error message itself, something like ERROR: <message>. Of course, this doesn't entirely eliminate the possibility of a false positive; what if you're processing a list of values starting with ERROR:? For now I decided to stick to the FileMaker way; if you'd rather have the error string, please use another wrapper that does exactly this.

About FileMaker errors#Back to top

If the plug-in calls one of FileMaker functions and receives an error, it cconverts in into a Python exception. Each error code has a dedicated exception class; the value of the exception is the standard string that describes the error code. For example, error 102, ‘Field is missing,’ will be reported so:

filemaker.MissingField: Field is missing.

The plug-in itself never raises any of FileMaker exceptions, it merely passes them along. But since all this happens in Python, developers can easily hijaak a FileMaker exception and add a custom value or even raise it from their owh code. I'm not sure if this is a good idea, especially the latter.