[Tutor] Impossible Else as Exception

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Apr 10 00:12:11 CEST 2013


On 9 April 2013 20:22, Jordan <wolfrage8765 at gmail.com> wrote:
> I want to know what exception should be raised if there is a bug in my code
> that allows an else statement to be triggered, because the else condition in
> my code should be impossible, unless there is an error in my code.  What
> exception should I raise so that if my code is wrong it will raise an
> exception which will give me a trace back?  Which would be most Pythonic?
>
> Example:
>
> if condition is 1:
>     do something with 1
> elif condition is 2:
>     do something with 2
> else: # Impossible unless the code above is flawed.
>     Raise Exception

AssertionError is raised when an assert statement fails. Since this
situation is essentially an implicit assert it would make sense to use
that.


Oscar


More information about the Tutor mailing list