catch error on writing to pipe and print