How do I know all thrown exceptions of a function?

Donn Cave donn at u.washington.edu
Mon Jan 22 19:40:57 EST 2001


Quoth "Delaney, Timothy" <tdelaney at avaya.com>:
...
| Here is my take on things:
|
| Four built-in exception classes, three of which form the basis for "trees"
| of exceptions:
|
| 	Exception
| 		type(Exception) == <type 'Exception'>
| 		used for "normal" exceptional circumstances - these
| 		need to be declared
|
| 		SilentException(Exception)
| 			type(SilentException) == <type 'SilentException'>
| 			used for things which should normally just pass
| 			through (such as index-out-of-bounds) - these don't
| 			need to be declared.
|
| 			UndeclaredException(SilentException)
| 				Raised when an undeclared Exception is
| raised
|
| 	Error
| 		type(Error) == <type 'Error'>
| 		used for "really bad" things which probably can't be
| 		recovered - these don't need to be declared
|
| A function needs to declare all the Exceptions it will raise. If a function
| raises an Exception it doesn't declare, instead an UndeclaredException is
| raised with the raised Exception as its data.
|
| SilentException is a subclass of Exception so you can continue to do
|
| try:
| except Exception:
|
| Things like index-out-of-bounds should be SilentException so they don't
| explicity need to be declared in just about every function around.
|
| There would be no requirement to catch any type of exception, whether
| declared or not.
|
| I think this covers all worries with backwards compatibility, whilst moving
| towards a well-defined exception system.

Could you explain more about what that does for you?

I don't understand "things which should normally pass through (such
as index-out-of-bounds)".  Pass through what?  When you later say
"so they don't need to be declared in just about every function around",
does that account for the whole reason behind SilentException?

I don't understand the distinction between Exception and Error.
Would you be able to catch Error the same as Exception?  If not,
what happens?  If you can catch them the same as Exception, then
it's just another category invented so you won't have to declare
the exception?

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list