Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercies: Raise My Exception

This is very similar to the exercise the first chapter about exceptions, but in this case you need to create your own hierarchy of exception classes.

  • Write a function that expects a positive integer as its single parameter.
  • Raise exception if the parameter is not a number.
  • Raise a different exception if the parameter is not positive.
  • Raise a different exception if the parameter is not whole number.
  • In each case make sure both the text and the type of the exceptions are different.
  • Include the actual value received as an attribute in the exception object.