Graphics2D Actor API

g2d.jlambda
Class Debugger

java.lang.Object
  extended by g2d.jlambda.Debugger

public class Debugger
extends Object

This class allows the JLambda user to tailor the level of verbosity in error reporting. It is used by the v command in the JLambda's read-eval-print loop. For the purposes of illustration there is a class in the util package Bugs:

 package g2d.util;

 public class Bugs {
     public static final int ZERO = 0;
     public static void loop(){
        loop();
     }
     public static int divideByZero(int x){
        return x / ZERO; 
     }
 }
 
This class is designed to have methods that throw unchecked exceptions, which from the point of view of the reflective interpreter simply result in failure:
 > (sinvoke "g2d.util.Bugs" "loop")
 Uncaught exception:
 sinvoke: method invocation failed
         Method = public static void g2d.util.Bugs.loop()
         Target = g2d.util.Bugs
 JLambda backtrace:
         computing result of sinvoke form @ line number 1
 
 >
 
As one can imagine this is not very helpful news when debugging, so to gain more information in such a situation one can look at the internal Java exceptions that were generated. One can either do this with the built in read-eval-print loop v command, or programmatically by:
> (sinvoke "g2d.jlambda.Debugger" "toggleVerbosity")
true
> 
To prevent seeing too much detail, we will also limit the printing of stack traces of the reported Java exceptions to a depth of 3 (the default is 15)
 > (sinvoke "g2d.jlambda.Debugger" "setStackDepth" (int 3))
 
and then, by re-executing the problem form, we see the real cause of the problem:
> (sinvoke "g2d.util.Bugs" "loop")
Uncaught exception:
sinvoke: method invocation failed
        Method = public static void g2d.util.Bugs.loop()
        Target = g2d.util.Bugs

Cause[0]: (class g2d.jlambda.EvaluateError)

        stack[0] = g2d.jlambda.InvokeCont.invokeMethod(InvokeCont.java:120)
        stack[1] = g2d.jlambda.InvokeCont.computeResult(InvokeCont.java:78)
        stack[2] = g2d.jlambda.EvalArgsCont.handleReturn(EvalArgsCont.java:42)
        stack[3] = g2d.jlambda.Continuation.ret(Continuation.java:66)
.... 6 more (see g2d.jlambda.Debugger to increase depth)

Cause[1]: (class java.lang.reflect.InvocationTargetException)

        stack[0] = sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        stack[1] = sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        stack[2] = sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        stack[3] = java.lang.reflect.Method.invoke(Method.java:585)
.... 10 more (see g2d.jlambda.Debugger to increase depth)

Cause[2]: (class java.lang.StackOverflowError)

        stack[0] = g2d.util.Bugs.loop(Bugs.java:7)
        stack[1] = g2d.util.Bugs.loop(Bugs.java:7)
        stack[2] = g2d.util.Bugs.loop(Bugs.java:7)
        stack[3] = g2d.util.Bugs.loop(Bugs.java:7)
.... 1021 more (see g2d.jlambda.Debugger to increase depth)
JLambda backtrace:
        computing result of sinvoke form @ line number 1

>
The underlying cause of the failure is stack overflow caused by the unguarded recursive call to loop.

Since:
June 29th 2005
Author:
Ian Mason

Method Summary
static Handler getHandler()
           
static int getStackDepth()
          Gets the depth to which stack traces of Java exceptions are printed.
static boolean getVerbosity()
          Gets the verbosity.
static void handle(Throwable e)
           
static void setHandler(Handler hndlr)
           
static void setStackDepth(int depth)
          Sets the depth to which stack traces of Java exceptions are printed.
static void setVerbosity(boolean b)
          Sets the verbosity.
static boolean toggleVerbosity()
          This toggles the verbosity flag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getHandler

public static Handler getHandler()

setHandler

public static void setHandler(Handler hndlr)

handle

public static void handle(Throwable e)

setStackDepth

public static void setStackDepth(int depth)
Sets the depth to which stack traces of Java exceptions are printed.

Parameters:
depth - an int specifying the stack depth value. The default is 15.
See Also:
getStackDepth()

getStackDepth

public static int getStackDepth()
Gets the depth to which stack traces of Java exceptions are printed. The default is 15.

Returns:
the depth to which the exception's stack trace is printed.
See Also:
setStackDepth(int)

setVerbosity

public static void setVerbosity(boolean b)
Sets the verbosity.

Parameters:
b - the desired level of verbosity.
See Also:
getVerbosity()

getVerbosity

public static boolean getVerbosity()
Gets the verbosity.

Returns:
the current level of verbosity.
See Also:
setVerbosity(boolean)

toggleVerbosity

public static boolean toggleVerbosity()
This toggles the verbosity flag. This flag determined whether or not the user gets to see all the exceptions caused by a particular JLambda evaluation error. It is this method that is called by the v command in the JLambda's read-eval-print loop.

Returns:
the resulting value of the boolean verbosity flag.

Graphics2D Actor API