Bird
0
0

Which of these is a valid way to raise a custom error with a message in Ruby?

easy📝 Conceptual Q2 of 15
Ruby - Error Handling
Which of these is a valid way to raise a custom error with a message in Ruby?
Athrow "Custom error occurred"
Braise "Custom error occurred"
Cerror "Custom error occurred"
Dfail! "Custom error occurred"
Step-by-Step Solution
Solution:
  1. Step 1: Identify Ruby keywords for errors

    Ruby uses raise and fail to throw errors, but fail is a synonym for raise.
  2. Step 2: Check syntax correctness

    raise "message" is the standard way to raise an error with a message. throw is different and not for errors, error is invalid.
  3. Final Answer:

    raise "Custom error occurred" -> Option B
  4. Quick Check:

    Raise with message = B [OK]
Quick Trick: Use raise with a string message to throw errors [OK]
Common Mistakes:
  • Using throw instead of raise
  • Using undefined error keyword
  • Confusing fail with error method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes