use try catch rather than passing errors as a reference