Answers for "try except block"

16

how to print error in try except python

try:
  # some code
except Exception as e:
	print("ERROR : "+str(e))
Posted by: Guest on November-19-2020
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
3

try except

try:
    print("I will try to print this line of code")
except:
    print("I will print this line of code if an error is encountered")
else:
    print("I will print this line of code if there's no error encountered")
finally:
    print("I will print this line of code even if there's an error or no error encountered")
Posted by: Guest on September-03-2021
3

try except python

try: #try to do the following
  print("Hi there")
except: #If what is meant to happen in (try) fails, do this.
  print("A error happened with the code above")
Posted by: Guest on September-29-2020
-1

try catch block

const input = require('readline-sync');

let animals = [{name: 'cat'}, {name: 'dog'}];
let index = Number(input.question("Enter index of animal:"));

try {
   console.log('animal at index:', animals[index].name);
} catch(err) {
   console.log("We caught a TypeError, but our program continues to run!");
   console.log("You tried to access an animal at index:", index);
}

console.log("the code goes on...");
Posted by: Guest on May-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language