Catch exceptions thrown when a template doesn't exist

Ticket: #5766