PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Returning error values/messages  (Read 1536 times)

PxPlus

  • Administrator
  • Diamond Member
  • *****
  • Posts: 1091
    • View Profile
Returning error values/messages
« on: May 31, 2018, 10:31:19 AM »
Often when writting generic routines it is desirable to not only return an error code but also an error message.

A simple technique that can be used to return a error condition and message to a calling application is to use one of the unused system error codes. Within PxPlus, error codes are in the range of from 0 to 255 however most errors code/message are below 200.

To return an application error; select one of these error codes (we suggest 250) and use it in an EXIT nnn directive to report an error to the user. To return an associated error message simply issue a DEF MSG(250)="My Error test" prior issuing the exit then the programmer can use MSG(250) to determine what the cause of the error was.

This has the added advantage that should the error cause the system to return to command mode, the error message will be displayed automatically.

For Example:

-:list
0010 ENTER TYPE$
0020 IF TYPE$<>"A" THEN GOTO BAD_TYPE
0030 ! ...
8000 BAD_TYPE:
8010 DEF MSG(250)="Unable to process Order - Wrong type"
8020 EXIT 250
-:save "tstord
C:\Pvxsrc\tstord
->call "tstord","B"
Unable to process Order - Wrong type
->print err
 250

This approach can be used for called sub-programs and objects.