Previous: , Up: Debugging  


6.8.3 Looking at Objects

When you are chasing an error, it is often helpful to examine the instance variables of your objects. While strategic calls to printNl will no doubt help, you can look at an object without having to write all the code yourself. The inspect message works on any object, and dumps out the values of each instance variable within the object.34

Thus:

   x := Interval from: 1 to: 5.
   x inspect

displays:

   An instance of Interval
   start: 1
   stop: 5
   step: 1
   contents: [
       [1]: 1
       [2]: 2
       [3]: 3
       [4]: 4
       [5]: 5
   ]

We’ll finish this chapter by emphasizing a technique which has already been covered: the use of the error: message in your own objects. As you saw in the case of Dictionary, an object can send itself an error: message with a descriptive string to abort execution and dump a stack backtrace. You should plan on using this technique in your own objects. It can be used both for explicit user-caused errors, as well as in internal sanity checks.


Footnotes

(34)

When using the Blox GUI, it actually pops up a so-called Inspector window.