Posts

Else & Finally In Try Except

Image
  try and except block: In the  try block , we write the code in which an exception might occur, and in  except block , we write the code as a result if an exception occurs. This could either be a print statement or the error itself. If no exception occurs, the except block will not execute. The purpose of try and except is to keep the program running either an error or exception occurs. In simple programs, if an error occurs, the program stops its execution and displays the error onto the screen. We can show the error as a string onto the screen by using try and except, and the program could continue its execution after that. For further explanation, you can give  Tutorial #24  a watch or read the description given below.   Figure1: try and except in Python else keyword:- Now moving on to the  else keyword . We use an else keyword to print something in cases where no exception occurs. Suppose that an exception occurred, and the except block is pr...