I'm not sure how much you're willing to do from the preamble, but here's a suggestion:
\documentclass{article}
\begingroup
\catcode`\.=\active
\gdef.{\normalperiod\allowbreak}%
\endgroup
\newcommand\aepath[1]{%%
\bgroup
\let\normalperiod=.%%
\catcode`\.=\active
\everyeof{\noexpand}%%
\endlinechar=-1%%
\ttfamily\scantokens{#1}%%
\egroup}
\let\oldtexttt\texttt
\let\texttt\aepath
\begin{document}
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown.
\end{document}
From your MWE, I assumed that you want your code to be breakable at points where a . occurs. Assuming that all situations where you might run into longish text involves such . separated names and that you do not need \texttt for any other purposes in your document, this might be a solution for you.
In case you might be concerned that another package might desire . to be active but defined differently, you could take the following approach:
\documentclass{article}
\begingroup
\catcode`\.=\active
\gdef\redefineperiod{\def.{\normalperiod\allowbreak}}%%
\endgroup
\newcommand\aepath[1]{%%
\bgroup
\let\normalperiod=.%%
\catcode`\.=\active
\redefineperiod
\everyeof{\noexpand}%%
\endlinechar=-1%%
\ttfamily\scantokens{#1}%%
\egroup}
\let\oldtexttt\texttt
\let\texttt\aepath
\begin{document}
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown. Followed
by more text which is just to fill to the ned of the line.
\end{document}
Naively (ie: this is what I initially thought I could do), you might try
\documentclass{article}
\newcommand\aepath[1]{%%
\bgroup
\let\normalperiod=.%%
\catcode`\.=\active
\def.{\normalperiod\allowbreak}%%
\everyeof{\noexpand}%%
\endlinechar=-1%%
\ttfamily\scantokens{#1}%%
\egroup}
\let\oldtexttt\texttt
\let\texttt\aepath
\begin{document}
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown. Followed
by more text which is just to fill to the ned of the line.
\end{document}
But this will fail because the period following \def has already been tokenized an is not active. So, LaTeX will throw an error about a missing control sequence.
UPDATE
If you're not particularly concerned about where the breaks occur then you can use something like:
\documentclass{article}
\makeatletter
\newcommand\aepath[1]{%%
\bgroup
\ttfamily
\ae@path#1\relax\@nil
\egroup}
\def\ae@path#1#2\@nil{%%
\def\ae@continue{}%%
\detokenize{#1}\unskip\penalty\z@
\ifx\relax#2%%
\else
\def\ae@continue{\ae@path#2\@nil}%%
\fi
\ae@continue}
\makeatother
\let\texttt\aepath
\begin{document}
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown.
\end{document}
though this seems a bit suboptimal to me. I think it would be better to decide where breakpoints should be and follow the example with . to make those characters (such as /, -, etc) into active characters within the context of the command and smuggle in the penalty to allow a break following them.
\documentclass{...}and ending with\end{document}. – Henri Menke Dec 25 '14 at 14:30\path), you can find alternative answers there which might help you (especially the one by Stefan Kottwitz). – cryingshadow Dec 25 '14 at 15:18urlpackage, the following\let\oldtexttt\texttt\let\texttt\pathas a possible work around which can be made from the preamble. – A.Ellett Dec 25 '14 at 15:24