Join Kevin Skoglund for an in-depth discussion in this video Exception methods, part of Ruby: Classes and Modules.
- [Narrator] In this movie I wanted to talk about…some of the exception methods.…After all, exceptions are classes…so it makes sense that they have methods.…Let's see how we can work with them.…The first thing we need to do is be able…to have an instance of that class and we can do that by…assigning the exception instance to a local variable…that we can use inside our rescue block.…The most common way to do that in Ruby is to,…at the end of the rescue line,…put what we call, the hash rocket or => together;…a lot like you have inside a hash.…
So it's pointing towards a local variable…and what we're doing is, we're saying take this exception…and assign it to that local variable and then…you'll be able to use it inside that rescue code block.…You can see here in this example,…I'm taking the ZeroDivisionError instance,…it's been raised, I'm assigning it to the variable e,…and then in my code I'm actually going to call e.class.…Now what is e.class?…Well it's ZeroDivisionError.…Notice that in the next line, I'm doing the same thing…
- Defining a custom class
- Working with instances of a class
- Class and instance attributes and methods
- Class inheritance
- Working with dates and times
- Using modules as namespaces and mixins
- Raising and handling exceptions
Skill Level Beginner
2. Class Attributes and Methods
4. Dates and Times
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.