| … | |
… | |
| 30 | else {reportEvalError($@) unless $f->{context}{error}{flag}} |
30 | else {reportEvalError($@) unless $f->{context}{error}{flag}} |
| 31 | return $v; |
31 | return $v; |
| 32 | } |
32 | } |
| 33 | |
33 | |
| 34 | # |
34 | # |
|
|
35 | # Call a subtroutine with error trapping. |
|
|
36 | # (We need to be able to do this from custom |
|
|
37 | # answer checkers and other MathObject code. |
|
|
38 | # PG_restricted_eval is not sufficient for this |
|
|
39 | # since that uses a string and so can't access |
|
|
40 | # local variables from the calling routine.) |
|
|
41 | # |
|
|
42 | sub Eval { |
|
|
43 | my $f = shift; |
|
|
44 | return unless defined($f); |
|
|
45 | eval {&$f(@_)}; |
|
|
46 | } |
|
|
47 | |
|
|
48 | # |
| 35 | # Remove backtrace and line number, since these |
49 | # Remove backtrace and line number, since these |
| 36 | # will be reported in the student message area. |
50 | # will be reported in the student message area. |
| 37 | # |
51 | # |
| 38 | sub Parser::reportEvalError { |
52 | sub reportEvalError { |
| 39 | my $error = shift; my $fullerror = $error; |
53 | my $error = shift; my $fullerror = $error; |
| 40 | $error =~ s/ at \S+\.\S+ line \d+(\n|.)*//; |
54 | $error =~ s/ at \S+\.\S+ line \d+(\n|.)*//; |
| 41 | $error =~ s/ at line \d+ of (\n|.)*//; |
55 | $error =~ s/ at line \d+ of (\n|.)*//; |
| 42 | Value->context->setError($error); |
56 | Value->context->setError($error); |
| 43 | if (Value->context->{debug}) { |
57 | if (Value->context->{debug}) { |