Debug - an error

From J Wiki
Jump to navigation Jump to search


<=   =>

Let's introduce an error into your centigrade verb to see how that looks and how you would find and fix it.

Open your cf.ijs script and edit the first line to have an error by adding quotes around the expression to the right of the copula.

t1 =. 'y - 32'

Instead of t1 being defined as the result of y - 32, it will be defined as the string.

Run the script to make the new definition. Turn off debug suspension and request no stops and then run your buggy centigrade.

   dbr 0	NB. disable suspension
   dbss ''
   centigrade 212 NB. Error messages in versions prior to J9.4 
|domain error
|   t2=.t1    *5

   centigrade 212    NB. Expanded error messages in J9.4 
|domain error in centigrade, executing dyad *
|x is character
|   t2=.t1    *5


You are executing with suspension disabled (dbr 0) so execution did not suspend in centigrade and you have the normal 3 space indent.

If you look at the line in error it is clear that the 5 is a valid argument to times, so there must be something wrong with t1. But you don't know the value of t1. You could stare at the source for the error, but, in a complex situation, it might be quicker to use debug.

Enable suspension and rerun.

   dbr 1	NB. enable suspension
   centigrade 212
|domain error
|   t2=.t1    *5
|centigrade[1]


There is a 6 space indent indicating suspension, and because centigrade is suspended you can look at the value of t1.

      t1
y - 32


From the display of t1 it is clear that it is a string, not the number from the desired calculation. You can now look at the source to see where t1 was defined and see that the quotes should not be there.

Edit the source to fix the definition by removing the quotes and run the script to redefine centigrade.

You want to run line 0 again to properly define t1. You can do this by using dbjmp to continue execution at line 0.

      dbjmp 0
100


Since no stops are set and there are no other errors, line 0 of centigrade is executed, which sets a proper value into local t1 and execution continues until finished.
<=   =>

Primer Index               Hover to reveal titles   -   Click to access   -   Current page is highlighted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
45 46 47 48
50 51 52 53 54 55 56 57
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
97 98 99 100 101 102 103 104 105 106