When an error has occurred or when you interrupt GAP (usually by
hitting ctrl-C) GAP enters a break loop, that is in most respects
like the main read eval print loop (see Main Loop). That is, you can
enter statements, GAP reads them, evaluates them, and shows the
result if any. However those evaluations happen within the context in
which the error occurred. So you can look at the arguments and local
variables of the functions that were active when the error happened and
even change them. The prompt is changed from gap> to brk> to
indicate that you are in a break loop.
gap> 1/0; Rational operations: divisor must not be zero Entering break read-eval-print loop, you can 'quit;' to quit to outer loop, or you can return a new divisor to continue
If errors occur within a break loop GAP enters another break loop at a
deeper level. This is indicated by a number appended to brk:
brk> 1/0; Rational operations: divisor must not be zero Entering break read-eval-print loop, you can 'quit;' to quit to outer loop, or you can return a new divisor to continue brk_02>
There are two ways to leave a break loop.
quit
The first is to quit the break loop.
To do this you enter quit; or type the eof (end of file) character,
which is usually ctrl-D.
Note that GAP code between quit; and the end of the input line
is ignored.
brk_02> quit; brk>
In this case control returns to the break loop one level above or
to the main loop, respectively.
So iterated break loops must be left iteratively.
Note also that if you type quit; from a gap> prompt, GAP will exit
(see Leaving GAP).
If you leave a break loop with quit without completing a command
it is possible (though not very likely) that data structures
will be corrupted or incomplete data has been stored in objects.
Therefore no guarantee can be given that calculations afterwards
will return correct results!
return [obj];
The other way is to return from a break loop. To do this you enter
return; or return expr;.
If the break loop was entered because you interrupted GAP,
then you can continue by entering return;.
If the break loop was entered due to an error,
you usually have to return a value to continue the computation.
For example, if the break loop was entered because a variable had no
assigned value, the value to be returned is the value that this variable
should have to continue the computation.
brk> return 9; # we had tried to enter the divisor 9 but typed 0 ... 1/9 gap>
OnBreak V
By default, when a break loop is entered, GAP prints a trace of the
innermost 5 commands currently being executed. This behaviour can be
configured by changing the value of the global variable
OnBreak. When a break loop is entered, the value of OnBreak is
checked. If it is a function, then it is called with no arguments. By
default, the value of OnBreak is Where (see Where).
gap> OnBreak := function() Print("Hallo\n"); end;
function( ) ... end
gap> Error("!");
Error !
Hallo
Entering break read-eval-print loop, you can 'quit;' to quit to outer loop,
or you can return to continue
brk>
Where( [nr] ) F
shows the last nr commands on the execution stack during whose execution the error occurred. If not given, nr defaults to 5.
gap> StabChain(SymmetricGroup(100));
# Here ^C was pressed
user interrupt at
S := S.stabilizer;
SiftedPermutation( S, (g * rep) ^ -1 ) called from
StabChainStrong( S.stabilizer, [ sch ], options ); called from
StabChainStrong( S.stabilizer, [ sch ], options ); called from
StabChainStrong( S, GeneratorsOfGroup( G ), options ); called from
StabChainOp( G, rec(
) ) called from
StabChainImmutable( arg[1] ) called from
<function>( <arguments> ) called from read-eval-loop
Entering break read-eval-print loop, you can 'quit;' to quit to outer loop,
or you can return to continue
brk> Where(2);
SiftedPermutation( S, (g * rep) ^ -1 ) called from
StabChainStrong( S.stabilizer, [ sch ], options ); called from
...
Note that the variables displayed even in the first line of the Where list
may be already one environment level higher and DownEnv (see DownEnv)
may be necessary to access them.
At the moment this backtrace does not work from within compiled code (this
includes the method selection which by default is compiled into the kernel).
If this creates problems for debugging, call GAP with the -M option
(see Advanced Features of GAP) to avoid loading compiled code.
(Function calls to Info and methods installed for binary operations are
handled in a special way. In rare circumstances it is possible therefore
that they do not show up in a Where log but the log refers to the last
proper function call that happened before.)
The command line option '-T' to GAP disables the break loop. This is mainly intended for testing purposes and for special applications. If this option is given then errors simply cause GAP to return to the main loop.
[Top] [Previous] [Up] [Next] [Index]
GAP 4 manual