throwing exception when errors occur