Ruby's technique of dealing with unforeseen events is through exceptions. You've seen exceptions in action if you've ever committed an error in your code, causing your application to crash with a message like SyntaxError or NoMethodError. When you throw a Ruby exception, the world comes to a halt and your software begins to shut down.
An exception is an unwelcome or unexpected occurrence that occurs during the execution of a program, i.e. at runtime, and disturbs the program's usual flow of instructions. In Ruby, descendants of the Exception class are used to connect raise methods to rescue statements in the begin and end blocks.
Create a brand new class. Exceptions, like everything else in Ruby, are classes!
Type a message in the box. A message attribute exists on every Ruby exception object.
To your exception, add a new data attribute. You can add custom data to your exception in the same way that you would to any other class.
Share a personalized message with your friends.