capture all errors and then print at the end