Replaced trigger_error with an exception