Which line is chosen to be reported in exception

Viewed 415

Suppose I have a multiline in Python which raises an Exception.

How does Python decide which line to raise the exception against?

Examples: (Note: I could have used backslashes \ after each line)

(1
 +0/0
 +3)

Thows an exception on line 3 (a ZeroDivisionError exception, at +3)).

(1
 +
 0/0
 )

Throws an exception on line 3.

(0/0
 +
 1)

Throws an exception on line 2.

This question was inspired by this example, and @Godman pointed out that exceptions don't just occur on the last line (as I had previously thought).

2 Answers
Related