Adding code to terminate pasting if an error is encountered.

Refs #1839