Python Forum
python multiple try except block in my code -- can we shorten code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python multiple try except block in my code -- can we shorten code
#11
Since Python 3.11 we got Zero Cost Exceptions.
If no exception is raised, there is nearly no loss in speed.
Only if an exception raises, it's slower.

It's ok to use try... except. Catching Exceptions too early is sometimes a problem.
It depends on the program itself and its organization.
+ it is OK to use Exceptions for control flow. Python is doing it aswell.

Fun fact 1: The control-flow of for-loops is realized with StopIteration. The iterator raises the StopIteration, if the iterator is exhausted.
Fun fact 2: A generator returns its result with a StopIteration and the result is stored in exception.args[0].
Larz60+ and Gribouillis like this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem Converting Tradingview Indicator to Python code kralxs 0 128 Apr-25-2024, 07:40 PM
Last Post: kralxs
  Equivalent Python code from VBA Mishal0488 2 796 Apr-19-2024, 10:32 AM
Last Post: masonsbore
  Why can I not see the code correctly in Python IDLE.? Trump 8 720 Apr-04-2024, 07:47 AM
Last Post: jonesphedra
Sad Selenium update broke python code genericusername12414 1 249 Mar-16-2024, 07:33 PM
Last Post: snippsat
  Algorithm for extracting comments from Python source code Pavel1982 6 542 Feb-28-2024, 09:52 PM
Last Post: Pavel1982
  Python best library for Excel reports & review of existing code MasterOfDestr 4 679 Feb-14-2024, 03:39 PM
Last Post: MasterOfDestr
Lightbulb python code debuging yunus 1 342 Feb-11-2024, 03:48 PM
Last Post: deanhystad
  Python code to set column width 1418 11 1,251 Jan-20-2024, 07:20 AM
Last Post: Pedroski55
  Python code for alignment and font size 1418 0 325 Jan-14-2024, 03:56 AM
Last Post: 1418
  python convert multiple files to multiple lists MCL169 6 1,567 Nov-25-2023, 05:31 AM
Last Post: Iqratech

Forum Jump:

User Panel Messages

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