I'm reviewing a few old macros of mine to make them fully expandable. One of the macros takes one argument, which should either be a two-digit or a four-digit integer (>1955). The macro then converts two-digit numbers to four-digit years in the range 1956-2055, and then goes on to do some other stuff (basically based on the difference between current year and the given year). I want to make this expandable since I want to be able to use it in for example `\href{mailto:foo\mymacro{98}bar@example.com}{Mail me!}`.

Now, reviewing the code, I can see that I used lots of assignments, but using `\numexpr` I can get rid of all of this, although at the cost of making the same computation several times as I branch through the different cases.

But I also used to have a bit of sanity checking: If `#1` is greater than 99 but smaller than 1956, I issue a `\PackageError` explaining the problem. If the sanity check holds, this is simply skipped, so its non-expandability is not a problem. Also, when used in ordinary text, the error works as expected. However, inside `\href`, the error becomes

```
Undefined control sequence.
\GenericError  ...                                
                                    #4  \errhelp \@err@     ...

```

which is not very helpful.

Is there a way to provide the user with an indication of the problem?

PS: I'm not sure if "expandable context" is the right way to describe the situation. Feel free to suggest a better title.

*Edit:* As an example, assume I want `\mymacro` to expand to the absolute value of the difference between the given year and `\year`. If the input is less than 100, we should interpret it as a year in the range 1956-2055. Input in the range 100-1955 should give an error. What I have now is something like

```
\def\mymacro#1{%
  \ifnum\numexpr#1>1955 %
    \ifnum\numexpr\year-#1\relax<0 %
      \number\numexpr#1-\year\relax
    \else
      \number\numexpr\year-#1\relax
    \fi
  \else
    \ifnum#1>99 %
      ERROR!%
    \else
      \ifnum#1>56 % 19xx
        \number\numexpr\year - 19#1\relax
      \else % 20xx
        \ifnum\numexpr\year - 20#1\relax<0 
          \number\numexpr20#1 - \year\relax
        \else
          \number\numexpr\year - 20#1\relax
        \fi
      \fi
    \fi
  \fi
}

%\def\test#1{#1: a\mymacro{#1}b}
\def\test#1{#1: \href{http://a\mymacro{#1}b}{Link}}
\test{96} \test{1996}; \test{08} \test{2008}; \test{11} \test{2011};
\test{20} \test{2020}

\test{123}

```

(the a and b are just there to check that spaces don't creep in). So I'd like to replace ERROR! by something which tells the user about the problem, preferably using a message that includes the offending `#1`.