[LON-CAPA-users] eval and trapping run-time errors in customresponse problems

Peter Riegler lon-capa-users@mail.lon-capa.org
Sun, 19 Sep 2010 19:05:00 +0200


Hi,

I am author of a customresponse problem which asks students to input a 
regular expression. The code contains as statement of the form
$somevariable =~ m/$submission/;
which results in a run-time error if the student's response (stored in 
variable $submission) is not a syntactically correct regular expression.
LON-CAPA handles this by returning "An internal error occurred while 
processing your answer. Please try again later."
In addition I receive a bomb message.

I have thought I could handle this by trapping the run-time error via 
something like

eval '$somevariable =~ m/$submission/';
return 'INCORRECT' if $@;

However it seems that eval in LON-CAPA does not assign its return value 
to $@. So $@ does not have a value interpreted as true.

Is there any way to catch run-time errors in LON-CAPA?

-- 
Peter Riegler
Fakultät Informatik
Ostfalia Hochschule für angewandte Wissenschaften
Fachhochschule Braunschweig/Wolfenbüttel
Salzdahlumer Str. 46/48
38302 Wolfenbüttel
Fon: ++49 5331 939 31540
http://public.rz.fh-wolfenbuettel.de/~riegler