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 With Friend
Have a friend to whom you would want to share this course?
Download LearnVern App
Code Scan
or
Download the app
598K+
Downloads
4.57
Avg. Ratings
15K+
Reviews
Learn anywhere on the go
Get regular updates about your enrolled or new courses
Share content with your friends
Evaluate your progress through practice tests
No internet connection needed
Enroll for the webinar and join at the time of the webinar from anywhere
Enjoying this course!
All the Courses on Learnvern are Free! So Register/Sign in to
have Access all the Courses and Videos.