home processing download documents tutorial python tutorial gallery source about
 Tutorials (back to the list of tutorials)

Debug

     Compile Error

When you "Run" Processing's sketch, there are two steps to go through internally to actually run the code.
  1. The first step is "compiling". This is a process to translate codes written as texts into executable binary files.
  2. The second step is to actually execute the executable binary files.
Error could happen during both steps.
If an error is found in the compiling process, Processing's sketch window (called PDE, Processing Development Environment) will tell you it had an error highlighting lines where the error is most likely to exist and will not open a new window to run the code.
When you run the code below, PDE shows compile error like below.

import processing.opengl.*;
import igeo.*;

size( 480, 360, IG.GL );

int i=0

The problem of the code above is actually the missing semicolon (;) at the end of "int i=0". The PDE window shows the compile error message of "unexpected token: int" and highlights the line of "int i=0". In this way, you can locate the place where it would contain errors and you can debug the errors.


     Print Debugging

Typical way of debugging in processing is print debugging. This is one of debugging method by the use of text output onto the console (in the case of Processing, the bottom black background area of PDE window).
You can print out text message while running your code by System.out.println() method, which is a Java's standard method to write out text message onto the console. Or, you can use iGeo's method IG.p(), which you can use exactly same way of System.out.println().

In print debugging, you insert the printing method to show the status of variables you are using in the code and check if the status of them is what you intend. You can also check the control flow of the code by checking if the printing method you insert is actually executed printing the message.

Example of print debugging with IG.p() is shown below.

import processing.opengl.*;
import igeo.*;

size( 480, 360, IG.GL );

int i=10;

IG.p("initial value of i =" + i );

i = 20;

IG.p("value of i at check point 1=" + i );

i = i*2;

IG.p("value of i at check point 2=" + i );

i = (i-i*2+3)/2;

IG.p("value of i at check point 3=" + i );

Please note that when you concatenate multiple data including String value, you use + to concatenate.

The error messages above are prefixed with "sketch_tutorial.setup: " which is a name of class and a name of method where the print method is inserted. If you need you can suppress this prefix by putting IG.disablePrintPrefix() method in the beginning of the code. Showing this prefix is useful when you have multiple methods and classes.


(back to the list of tutorials)

HOME
FOR PROCESSING
DOWNLOAD
DOCUMENTS
TUTORIALS (Java / Python)
GALLERY
SOURCE CODE(GitHub)
PRIVACY POLICY
ABOUT/CONTACT