# Is there a 'try' command for LaTeX? [duplicate]

What I'm trying to do is input file1 if it exists and input file2 otherwise, without having to deal with an 'I can't find file' error. I would like to accomplish this using TeX, without using symbolic links. What I would like is some kind of `\try` command:

``````\try{\input{file1}}
\catch{\input{file2}}
``````

Of course, this would try to input file1 and, if it encounters an error, input file2 instead.

I'm sure people who are more proficient than I am with plain TeX could accomplish this easily.

(Please feel free to edit the tags.)

-

## marked as duplicate by lockstep, T. Verron, Stephen, Werner, KurtFeb 28 '13 at 21:05

There's an `\InputIfFileExists`, see e.g. how do I use the \input command on windows, combined with \IfFileExists? –  Torbjørn T. Feb 28 '13 at 20:25
A poor man's attempt at conditioning: `\IfFileExists{fileA.tex}{\input{fileA.tex}}{\input{fileB.tex}}`; `\InputIfFileExists` does exactly this. –  Werner Feb 28 '13 at 20:30
Excellent! Thank you. Should I close this question, then? –  Z Norwood Feb 28 '13 at 20:31
I dunno. I think try/catch functionality in LaTeX would be useful, if possible. I have my doubts though, since all the languages I can think off with that feature have a thin over-layer as sort of a dispatcher. –  Sean Allred Feb 28 '13 at 20:33