Python Forum
Handling exception from a module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling exception from a module
#1
Very new to python, grew up on PHP. I'm using the pdftitle module, for its intended purpose, don't seem to be able to gracefully handle it throwing exceptions.

Exceptions I've come across are either recursion limit or "pdfminer.pdffont.PDFUnicodeNotDefined". I'm happy to just skip the documents where these occur but have been unable to. Not sure if the cause us "During handling of the above exception, another exception occurred:" or overall nesting from the module?

try:
    PdfTitle = pdftitle.run(FilePath)
except:
    print(FilePath)
    print("an exception occurred")
Expected result - file name and "an exception occurred" are printed, actual result is the exception output:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\pdfminer\pdffont.py", line 580, in to_unichr
    return self.cid2unicode[cid]
KeyError: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python38-32\lib\s
...
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\pdfminer\pdffont.py", line 582, in to_unichr
    raise PDFUnicodeNotDefined(None, cid)
pdfminer.pdffont.PDFUnicodeNotDefined: (None, 1)
Reply


Messages In This Thread
Handling exception from a module - by dchi2 - Nov-23-2019, 09:18 AM
RE: Handling exception from a module - by Larz60+ - Nov-23-2019, 09:23 AM
RE: Handling exception from a module - by dchi2 - Nov-23-2019, 10:51 PM
RE: Handling exception from a module - by Larz60+ - Nov-23-2019, 11:12 PM
RE: Handling exception from a module - by dchi2 - Nov-23-2019, 11:35 PM
RE: Handling exception from a module - by Larz60+ - Nov-23-2019, 11:50 PM
RE: Handling exception from a module - by dchi2 - Nov-23-2019, 11:58 PM
RE: Handling exception from a module - by Larz60+ - Nov-24-2019, 03:32 AM
RE: Handling exception from a module - by dchi2 - Nov-24-2019, 05:23 AM
RE: Handling exception from a module - by Larz60+ - Nov-24-2019, 08:31 AM
RE: Handling exception from a module - by dchi2 - Nov-24-2019, 09:40 AM
RE: Handling exception from a module - by dchi2 - Nov-25-2019, 08:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Star python exception handling handling .... with traceback mg24 3 1,327 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  TicTacToe Game Add Exception Handling and Warning Function ShaikhShaikh 5 2,477 Nov-03-2021, 05:02 PM
Last Post: deanhystad
  Error handling using cmd module leifeng 3 2,947 Jun-06-2020, 06:25 PM
Last Post: leifeng
  Exception handling in regex using python ShruthiLS 1 2,389 May-04-2020, 08:12 AM
Last Post: anbu23
  Exception handling Calli 2 2,498 Apr-20-2020, 06:13 PM
Last Post: Calli
  problem using custom exception handling in python srm 3 3,098 Jul-03-2019, 09:10 PM
Last Post: ichabod801
  an easy way to disable exception handling Skaperen 6 5,529 Jun-02-2019, 10:38 PM
Last Post: Gribouillis
  exception handling KyawMyo 3 2,908 May-07-2019, 07:53 AM
Last Post: buran
  Database operation exception handling LostInCode 1 2,520 Jan-03-2019, 07:50 PM
Last Post: jeanMichelBain
  During handling of the above exception, another exception occurred Skaperen 7 26,995 Dec-21-2018, 10:58 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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