Just to illustrate the suggestion I made in a comment:
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\newcommand*{\ensureLineHasEnded}{\ifvmode \else \expandafter \\\fi}
\newcommand*{\NLhline}{\ensureLineHasEnded\hline}
\begin{document}
\noindent
\begin{tabular}{|l|}
\hline
A one-column \texttt{tabular}, just for demo purposes. \\
\NLhline
It uses both vertical and horizontal rules (arrggh\ldots!). \\
\NLhline
But some of the \verb|\\|~commands are missing\ldots
\NLhline
\ldots yet the horizontal rules are typeset normally. \\*[6pt]
\NLhline
The \verb|\ensureLineHasEnded| can take the same optional arguments\ldots
\ensureLineHasEnded*[6pt]\hline
\ldots as the \verb|\\|~command.
\NLhline
Moreover, it works as expected when used at the end of the \texttt{tabular}.
\ensureLineHasEnded[9pt]
\end{tabular}\par
\end{document}
Edit: As David Carlisle has remarked, the \ifvmode test does not work if p-type columns are used, because TeX is in vertical mode in these columns too. Note that, more precisely, TeX is internal vertical mode both inside p-type columns and between the lines of an alignment (The TeXbook, p. 282), so a supplementary \ifinner test wouldn’t help either. A distinction that does work in simple situations is based on the current group level, which can be enquired about by means of the e-TeX primitive \currentgrouplevel.
The following code is just a proof of concept: there’s little point in refining it unless you know the precise context into which it’s going to be used.
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\makeatletter
\@ifdefinable\@tabular@group@level{\newcount\@tabular@group@level}
\newcommand*\ensureLineHasEnded{%
\ifnum \currentgrouplevel>\@tabular@group@level
% % Diagnostics:
% \count@ \currentgrouplevel
% \typeout{Inserting \protect\\ at line \number\inputlineno,
% since \number\count@\space > \number\@tabular@group@level}%
\expandafter \\%
\fi
}
\newcommand*\saltAwayLevel{%
\noalign{%
\global \@tabular@group@level
\numexpr \currentgrouplevel -\@ne \relax
% % Diagnostics:
% \typeout{\number\@tabular@group@level}
}%
}
\makeatother
\newcommand*{\NLhline}{\ensureLineHasEnded\hline}
\begin{document}
With \texttt{l}~columns:
\begin{center}
\begin{tabular}{|l|}
\saltAwayLevel
\hline
A one-column \texttt{tabular}, just for demo purposes. \\%
\NLhline
It uses both vertical and horizontal rules (arrggh\ldots!). \\
\NLhline
But some of the \verb|\\|~commands are missing\ldots
% \typeout{\number\currentgrouplevel}%
\NLhline
\ldots yet the horizontal rules are typeset normally. \\*[6pt]
\NLhline
The \verb|\ensureLineHasEnded| can take the same optional arguments\ldots
\ensureLineHasEnded*[6pt]\hline
\ldots as the \verb|\\|~command. \\
\NLhline
Moreover, it works as expected when used at the end of the \texttt{tabular}.
\ensureLineHasEnded[9pt]
\end{tabular}\par
\end{center}
\bigbreak
With \texttt{p}~columns:
\begin{center}
\begin{tabular}{|p{.9\linewidth}|}
\saltAwayLevel
\hline
A one-column \texttt{tabular}, just for demo purposes. \\%
\NLhline
It uses both vertical and horizontal rules (arrggh\ldots!). \\
\NLhline
But some of the \verb|\\|~commands are missing\ldots
% \typeout{\number\currentgrouplevel}%
\NLhline
\ldots yet the horizontal rules are typeset normally. \\*[6pt]
\NLhline
The \verb|\ensureLineHasEnded| can take the same optional arguments\ldots
\ensureLineHasEnded*[6pt]\hline
\ldots as the \verb|\\|~command. \\
\NLhline
Moreover, it works as expected when used at the end of the \texttt{tabular}.
\ensureLineHasEnded[9pt]
\end{tabular}\par
\end{center}
\end{document}
You can uncomment the diagnostic commands to get additional information on what is going on.
\\TeX is in vertical mode, and this condition can be tested with\ifvmode. – GuM Jul 05 '17 at 18:15