Catch exceptions and encode term