Python Forum
PiCamera - print exceptions?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PiCamera - print exceptions?
#1
Hello ,
I'm trying to handle exception but it said
NameError: name 'Picamera' is not defined
what did I miss?

from picamera import PiCamera

try:
        camera = PiCamera()
except picamera.PiCameraError:
        print('Camera problem')
        return ('Camera problem')
except picamera.PiCameraMMALError:
        print('error1')
        return ('ERRRORR')
except Exception as e:
        print(e)
        return(e)
Thanks ,
Reply
#2
You imported PiCamera. Nowhere do you import picamera.
Reply
#3
what DeanStad is telling you is that lines 5 and 8 are referencing the Package name and not the instance.
for example, line 5 should read except PiCamera.PiCameraError:
same for line 8

A better way, and the one recommended by the author would be:
import picamera


with picamera.PiCamera() as camera:
    try:
        camera.brightness = int(some_user_value)
    except PiCameraError:
        print('Something went wrong with the camera')
    # etc.
assign exceptions to the individual actions, don't try to capture all in one place.
see: https://picamera.readthedocs.io/en/relea...i_exc.html
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Class exceptions DPaul 1 1,303 Mar-11-2022, 09:01 AM
Last Post: Gribouillis
  is this a good way to catch exceptions? korenron 14 4,734 Jul-05-2021, 06:20 PM
Last Post: hussaind
  Split recording with Picamera EvanS1 0 1,939 Jun-19-2021, 12:26 PM
Last Post: EvanS1
  Python, exceptions KingKhan248 6 3,057 Nov-15-2020, 06:54 AM
Last Post: buran
  Split string between two different delimiters, with exceptions DreamingInsanity 2 2,051 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity
  handling 2 exceptions at once Skaperen 2 2,322 Jun-27-2020, 08:55 AM
Last Post: Yoriz
  remove spaces with exceptions catosp 4 2,425 May-29-2020, 09:32 AM
Last Post: catosp
  Looking for advice and Guidance on Exceptions used within Functions paul41 1 2,165 Nov-14-2019, 12:33 AM
Last Post: Larz60+
  multi-line messages in raised exceptions? Skaperen 3 7,362 Aug-01-2019, 02:17 AM
Last Post: Skaperen
  picamera not working on premade script georgeaura 1 2,537 Jul-24-2019, 10:11 AM
Last Post: gontajones

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020