Join Kevin Skoglund for an in-depth discussion in this video Custom exceptions, part of Ruby: Classes and Modules.
- [Instructor] In the previous movie,…we learned how we can raise exceptions in our own code…and we did that using Ruby's built-in exceptions.…In this movie I want us to learn how to define…our own custom exception classes.…Defining a custom exception class,…is as simple as inheriting from one…of Ruby's built-in exception classes,…and the one you probably want to pick is StandardError.…You'll remember that StandardError is the default…for rescuing so, when we call rescue with nothing after it,…it's going to rescue StandardError and all of its subclasses.…
So we probably want to make our custom error,…be one of those subclasses so that it also gets rescued.…So that's all we have to do, we know about class inheritance…so we're just simply creating a new class…that inherits everything from StandardError,…and it saves us from creating…a lot of other code from scratch.…Then when we want to use it, we just simply raise it.…So here I have my Radio class and if the value…for the volume is greater than 10,…it's going to raise my new custom exception TooLoudError.…
- 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.