Python - Add message to user exception

Introduction

You can attach state information and methods to your own exception.

They can customize their error message text displayed if they're not caught:

Demo

class Career(Exception): 
     def __str__(self): return 'So I became a waiter...' 

raise Career()# w  w  w.  ja  v  a2  s. co  m

Result

Related Topic