Your idea is right, but the way you call it is wrong. It should be
raise MyCustomError.new(an_object, "A message")
Your idea is right, but the way you call it is wrong. It should be
raise MyCustomError.new(an_object, "A message")