> Has anyone any idea how can I do the following without any
> errors, or at least get the same result using any other approach?
>
> \footnote{foo \verb|bar| foo}
>
> \section{foo \verb|bar| foo}

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=verbwithin

the answer is different in your two cases.