Testing if errors are thrown at correct places