Custom Error Message

This shows how to customize (remap) the error messages students receive after submitting an incorrect response or making a syntax error when entering their answer.

Complete Code

Download file: ErrorMessageCustomization.pg

PG problem file

Explanation

DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');

Preamble

These standard macros need to be loaded.
Context()->{error}{msg}{"Missing operand after '-'"} =
    "Enter '-1' instead of '-'";

$ans1 = Real(-1);
$ans2 = Formula("x-2");

Setup

To update the error message, the string in the Context()->{error}{msg} hash must match exactly and then is replaced with the customized version.

BEGIN_PGML
Factor [`-1`] from [`-x+2`]

[`-x+2 =`] [__]{$ans1} [`\cdot \big(`] [__]{$ans2} [`\big)`]
END_PGML

Statement

This is the problem statement in PGML.
BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.