Skip to content

Commit

Permalink
Fix samples using GetDescription() on exceptions
Browse files Browse the repository at this point in the history
try:
  ..
except py.GenericException as e:
  print(e.GetDescription())

never worked, as the description string is already
set as message of the raised python exception

try:
  ..
except py.GenericException as e:
  print(e)

is sufficient
  • Loading branch information
thiesmoeller committed Aug 30, 2023
1 parent 1fd8160 commit a6d3867
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion samples/grab.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
except genicam.GenericException as e:
# Error handling.
print("An exception occurred.")
print(e.GetDescription())
print(e)
exitCode = 1

sys.exit(exitCode)
2 changes: 1 addition & 1 deletion samples/grabcameraevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ def OnImageGrabbed(self, camera, grabResult):

except genicam.GenericException as e:
# Error handling.
print("An exception occurred.", e.GetDescription())
print("An exception occurred.", e)
2 changes: 1 addition & 1 deletion samples/grabchunkimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ def OnImageGrabbed(self, camera, grabResult):

except genicam.GenericException as e:
# Error handling.
print("An exception occurred.", e.GetDescription())
print("An exception occurred.", e)
exitCode = 1
2 changes: 1 addition & 1 deletion samples/grabmultiplecameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

except genicam.GenericException as e:
# Error handling
print("An exception occurred.", e.GetDescription())
print("An exception occurred.", e)
exitCode = 1

# Comment the following two lines to disable waiting on exit.
Expand Down
2 changes: 1 addition & 1 deletion samples/grabusinggrabloopthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ def OnImageGrabbed(self, camera, grabResult):
break
except genicam.GenericException as e:
# Error handling.
print("An exception occurred.", e.GetDescription())
print("An exception occurred.", e)
2 changes: 1 addition & 1 deletion samples/guiimagewindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
except genicam.GenericException as e:
# Error handling.
print("An exception occurred.")
print(e.GetDescription())
print(e)
2 changes: 1 addition & 1 deletion samples/helloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def main():

return 0
except genicam.GenericException as e:
print("Error ", e.GetDescription())
print("Error ", e)

return -1

Expand Down
2 changes: 1 addition & 1 deletion samples/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@

except genicam.GenericException as e:
# Error handling.
print("An exception occurred.", e.GetDescription())
print("An exception occurred.", e)

camera.Close()
4 changes: 2 additions & 2 deletions samples/utilityimageformatconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ def show_image(image, message):
targetImage.Save(pylon.ImageFileFormat_Png, filename)

except genicam.GenericException as e:
print("Could not grab an image: ", e.GetDescription())
print("Could not grab an image: ", e)
except genicam.GenericException as e:
print("An exception occurred. ", e.GetDescription())
print("An exception occurred. ", e)
4 changes: 2 additions & 2 deletions samples/utilityimageformatconverter1.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def grab_image():
camera.Close()
return result
except genicam.GenericException as e:
print("Could not grab an image: ", e.GetDescription())
print("Could not grab an image: ", e)


try:
Expand Down Expand Up @@ -67,4 +67,4 @@ def grab_image():
target_image = converter.Convert(image)
show_image(target_image, "Converted image.")
except genicam.GenericException as e:
print("An exception occurred. ", e.GetDescription())
print("An exception occurred. ", e)

0 comments on commit a6d3867

Please sign in to comment.