WeBWorK Problems

difficulty catching and replacing error message

difficulty catching and replacing error message

by John Sylvester -
Number of replies: 3
I would like to catch and replace an error message. My best description of the problem is in the attached file, UndetCoeffCheckerTest.pg. If you run it, and paste "incorrectanswer2" in the answer blank, you will see the error message I want to replace. I included explanations of what I am trying to do throughout the file. I apologize for its length. The second file, UndeterminedCoeff.pg, is included just in case you are wondering what purpose this answer checker serves. I've included as .tar because I didn't know how to include two files.

I have tried "withPostFilter" but I don't understand the syntax well enough, or even if it could work with my answer checker.

Thanks for your time.
In reply to John Sylvester

Re: difficulty catching and replacing error message

by Davide Cervone -
You could do it with withPostFilter, but it is probably easier to trap the error in the line that is causing it. So you could replace
if ($studentH != $y[$i])
     {Value->Error("c[$i] term not right")}
with
my $result = Parser::Eval(sub {$studentH == $y[$i] ? 1 : 0});
Value->Error("Can't check equality") unless defined($result);
Value->Error("c[$i] term not right") unless result;
(using whatever message you want).

Note that you will need to do something similar a few lines later with the ($studentwp != $yforced check.

In reply to Davide Cervone

Re: difficulty catching and replacing error message

by John Sylvester -
Many, Many, Many thanks. Its working perfectly now.

One related question:
I have switched from
 "Value->Error("mymessage")
to
{$self->{ans_message} =
 "mymessage";
return 0;}

because, in these cases, the student has answered incorrectly and I want this counted as an incorrect answer. My impression is that the Value->Error construction does not grade the problem, but the latter construction does?

Is this correct?

thanks again

In reply to John Sylvester

Re: difficulty catching and replacing error message

by Davide Cervone -
> My impression is that the Value->Error construction does not grade the problem, but the latter construction does?

Well, yes, it's true that Value->Error() doesn't set the score, but the MathObject answer checker explicitly sets the score to 0 prior to calling your checker, so there is no need for you to return a value if you want to score to be 0 when you produce the error. Just calling Value->Error() is perfectly fine, and in fact is how all the MathObject answer checkers report errors. So if there were a problem with this, it would have been apparent long ago.