Python Forum
Custom method to handle exceptions not working as expected
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom method to handle exceptions not working as expected
#2
This won't work because in the line
title = get_element(title_selector[0].text, 'Untitled') # Returns first element in title_selector if there is one; if IndexError returns 'Untitled'
that is where the IndexError will be raised before it gets to the function as it is trying to index the list

You could check if the list is empty
if not title_selector:
    title = 'Untitled'
else:
    title = whatever_you_want_to_do_instead
Reply


Messages In This Thread
RE: Custom method to handle exceptions not working as expected - by Yoriz - Dec-22-2022, 06:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  "Random" module is not working as expected Genericgamemaker 1 981 Jul-25-2024, 04:46 PM
Last Post: Gribouillis
  Python trivial endgame engine is not working as expected max22 0 1,170 Feb-24-2024, 04:41 PM
Last Post: max22
  Simple conditional not working as expected return2sender 8 2,458 Aug-27-2023, 10:39 PM
Last Post: return2sender
  Method works as expected on host machine but not on server gradlon93 4 2,065 Jan-05-2023, 10:41 AM
Last Post: DeaD_EyE
  PiCamera - print exceptions? korenron 2 1,555 Dec-15-2022, 10:48 PM
Last Post: Larz60+
Exclamation My code is not working as I expected and I don't know why! Marinho 4 2,247 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  Class exceptions DPaul 1 1,926 Mar-11-2022, 09:01 AM
Last Post: Gribouillis
Question Having trouble writing an Enum with a custom __new__ method stevendaprano 3 7,978 Feb-13-2022, 06:37 AM
Last Post: deanhystad
  set and sorted, not working how expected! wtr 2 2,058 Jan-07-2022, 04:53 PM
Last Post: bowlofred
  is this a good way to catch exceptions? korenron 14 7,200 Jul-05-2021, 06:20 PM
Last Post: hussaind

Forum Jump:

User Panel Messages

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