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()# from w w w .  j  a  v a 2 s  .com

Result

Related Topic