you should use a try/ catch block around civicrm_api3 call as it won't return an array if it hits an error