Skip to content

Commit 0711965

Browse files
author
Jakub Kaczmarzyk
authored
bf: preserve error output if not valid klass
The scope of variable `e` in `except Exception as e` is the `except block` in python3. Trying to raise it out of the `except` block will raise an `UnboundLocalError`.
1 parent e48b746 commit 0711965

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

nibabel/loadsave.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ def save(img, filename):
133133
converted = klass.from_image(img)
134134
break
135135
except Exception as e:
136-
continue
136+
err = e
137137
# ... and if none of them work, raise an error.
138138
if converted is None:
139-
raise e
139+
raise err
140140

141141
# Here, we either have a klass or a converted image.
142142
if converted is None:

0 commit comments

Comments
 (0)