Course Content

Course Content


We use rescue clauses to inform Ruby what types of exceptions we want to manage, and we wrap the code that could raise an exception in a begin/end block.

By invoking Kernel#raise, Ruby really offers you the ability to manually raise exceptions. This gives you the option of selecting the type of exception to raise and even customising the error message. If you don't specify an exception type, Ruby will raise a RuntimeError by default (a subclass of StandardError ).

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 an exception in Ruby, everything comes to a halt and your programme begins to shut down.

Exceptions are the results of breaking a rule. There are two types of exceptions:

  • Syntactic exceptions, which break the rules of grammar and syntax.
  • Semantic exceptions, which break the rules of meaning.

An exception is a signal that something has gone wrong in your code. You can create an exception by using the raise method.

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
Apple App Store
598K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
15K+ Reviews
App Download Section Circle 3
  • 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