# Error Handling and Debugging

Additional Debugging Procedures |

While Error Codes and Messages and the Windows Debugging Environment provide the most obvious means for finding errors in syntax and logic, a few other facilities can be employed to handle or prevent programming problems.

#### Note:
For debugging procedures involving the installation, start up and configuration of PxPlus, see Troubleshooting.

## Current State Information (Windows)

For a quick look at the current state of the PxPlus version installed on your system, select the About PxPlus option from the PxPlus icon drop-down menu, then click the Info button.

The PxPlus Current State Information window is displayed with information that includes the version number and build date, current date, program backtrace, list of all open files, and a list of all active OOP objects. Update contents by clicking the Refresh button.

#### Note:
This feature is only available with PxPlus for Windows.

## PxPlus Log File

The PxPlus log file is used to provide a more detailed breakdown of internal errors that are encountered by PxPlus on Windows and UNIX/Linux platforms.

When defining the log file, you can specify the maximum size you want the log file to grow by appending a , (comma) followed by the maximum file size (in megabytes) to your log file pathname. Once the log file reaches this size, it will be renamed automatically by suffixing it with ".1", and a new log file will be created. Any prior log files ending with ".1" will be renamed with ".2", ".2" will be renamed with ".3" and so on up to ".5". The log file ending with ".5" will not be renamed ".6"; instead, it will be removed from the system. A total of six log files can be created (i.e. the current log file with no suffix, and the five prior log files with suffixes .1 through .5). This total number is fixed and cannot be changed.

(The ability to define the maximum log file size was added in PxPlus 2022.)

The log file is activated by adding a LogFile=filename entry (without quotes) to the PxPlus INI file under the [Config] section. For information on defining the LogFile entry, see INI Contents.

In the UNIX environment, it can also be enabled by the existence of a file called pvxtrace.log. If the file exists when PxPlus attempts to add the first entry, then entries are appended to this file. If it does not exist, the logging feature is disabled for the balance of the PxPlus session.

All entries in the log file are displayed using the following format:

> mmm dd hh:mm [progname:stmt#]errormsg

Where:

| mmm dd hh:mm | Date and time of the entry
| progname:stmt# | Name of the program and statement executing when the entry was added
| errormsg | Actual descriptive message

Example:

> Sep 15 16:52 [*ntslave:0320] [TCP][Winsock]Error status:10049 (-1)

Entries in the log for TCP/IP issues include a descriptive message, followed by the actual TCP/IP error code and the socket number that was being used. A socket value of -1 usually indicates the OPEN was not successful.

## Creating a Log File to Trap System Failures

Whenever an application failure occurs within PxPlus (GPF, Segmentation fault, etc.), the system will attempt to record key system information on the system LogFile in the hopes it will provide insight as to what caused the failure. Given this, if you are having problems, you should assign a log file to your tasks to assist in problem resolution; however, managing these log files can be problematic.

One simple solution is to create individual log files for each process, place these in a separate directory and have the system delete them if the process normally terminates.

The following code is an example of some logic you can use to accomplish this:

> x$="log_directory/log."+dte(0:"MMDD-%Hz%mz")+"."+str(tcb(89))+".txt
> serial x$
> setdev (0) set "Logfile" to x$

> open (gfn) x$
> setdev (lfo) set "DeleteOnClose" to "Yes"

Basically, the logic creates a unique log file name based on the date, time and process ID and assigns it as the application LogFile. To have the system automatically delete the file when the session closes, OPEN the file on a global channel and then set its "DeleteOnClose" property so that when the PxPlus shuts down normally, the file will be deleted.

Should the PxPlus process terminate abnormally for any reason, the DeleteOnClose will not occur, leaving the failing LogFile on the system for subsequent analysis.

#### Note:
If desired, you can have your application also write information to this LogFile using SETTRACE RECORD string$. See SETTRACE directive.

## Logical Line Labels

While logical line labels do not qualify as debugging options, they can reduce potential difficulties caused by renumbering programs and can simplify the development of programs without line numbers.

See Labels/Logical Statement References.

## Generic Escape Key Handling

Using the following syntax, an application can intercept Esc keys system wide:

> SETESC prog_name$

The SETESC directive takes precedence over the generic escape key handler.

## For ODBC-Related Problems

The '!Q'= system parameter can be used to show all of the SQL commands being executed in a Windows message box. The OK/Cancel option allows a programmer to disable the message boxes by selecting Cancel.