% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}

\usepackage[docdef=restricted,
 undefaction=warn
 ]{glossaries-extra}

\makeglossaries

\begin{document}

\newglossaryentry{sample}{name={sample},description={an example}}

\gls{sample}.

\printglossaries

Too late to define an entry with the \texttt{docdef=restricted}
setting. (Definitions must come before \verb|\printglossary|.)

\newglossaryentry{sample2}{name={sample2},description={another
example}}

New entry just defined: \gls{sample2}.
This will cause an error (or warning with \texttt{undefaction=warn})
in \verb|\printglossaries|.
This missing entry will be marked with two question marks ?? 
in the glossary.


\end{document}
