Answers for "try inside except python"

22

python try catch

try:
  # Dangerous stuff
except ValueError:
  # If you use try, at least 1 except block is mandatory!
  # Handle it somehow / ignore
except (BadThingError, HorrbileThingError) as e:
  # Hande it differently
except:
  # This will catch every exception.
else:
  # Else block is not mandatory.
  # Dangerous stuff ended with no exception
finally:
  # Finally block is not mandatory.
  # This will ALWAYS happen after the above blocks.
Posted by: Guest on June-25-2020
2

try except python

# Python try: except:

try:
  print(a + b) # Program will try the add b to a
except:
  print("There was an error") # If the program will have an error in the try block
  							  # The except block will run
    						  # except block will run and then the program will continue to run
    
# Examples:
a = 1
b = 1 # <===== no error, except block skipped

a = 1
b = 'one' # <===== error, except block run
Posted by: Guest on January-10-2021
0

python is running both try and except statement

elif 'where am i' in query or 'where we are' in query:
            speak("wait sir let me check")
            try:
                ipAdd = requests.get('https://ipinfo.io/').text
                print(ipAdd)
                data = ipAdd.json()
                #print(geo_data)
                city = data['city']
                # state = geo_data['state']
                country = data['country']
                speak(f'sir i m not sure but i think we are in {city} city of {country} country')
            except Exception as e:
                speak("sorry sir but due to network issues i m not able to found where we are")
                pass
Posted by: Guest on September-13-2021

Python Answers by Framework

Browse Popular Code Answers by Language