<jupyter_start><jupyter_text>ERRORS AND EXCEPTION HANDLING try : This will contain the block of code which is to executed and may lead to generate error. except : This block of code is to executed if there is any error in try block. finally : A final block of code will be executed regardless of an error.  Syntax<jupyter_code>#try:
    #Block of code to be executed which may lead to an error
#except:
    #If error is generated then execute this block of code.
#finally:
    #This block will be executed regardless of an error or not.
# Add function
def add(num1,num2):
    print('Result:',num1+num2)
add(2,3)
#error will be generated because the num2 here is string
num1=10
num2=input('Enter number:')
add(num1,num2)
def add(num1,num2):
    try:
        print('Result:',num1+num2)
    except:
        print('Please make sure that both inputs are of same data type')
    finally:
        print('We executed finally')
add(10,20)
add(10,'20')<jupyter_output>Please make sure that both inputs are of same data type
We executed finally<jupyter_text>Try Except and Else<jupyter_code>def add_num(num1,num2):
    try:
        add = num1 + num2
    except:
        print('''This isn't look good! Please check again. ''')
    else:
        print('Addition went well.')
        print('Result:',add)
add_num(10,20)
add_num(10,'10')<jupyter_output>This isn't look good! Please check again.<jupyter_text>There are many type of errors that can be generated while executing a block of code. Check the python documentation of Errors and Exception Handling (Built in Errors ) for more info.  Try Except Else and Finally.<jupyter_code>def divide_num(num1,num2):
    try:
        k=num1/num2
    except:
        print('Wrong Input!!!')
    else:
        print('Result:',k)
    finally:
        print('Divide_num() is executed')
divide_num(2,'4')
divide_num(2,0)
divide_num(44,2)<jupyter_output>Result: 22.0
Divide_num() is executed
{'fraction_non_alphanumeric': 0.0961337513061651, 'fraction_numerical': 0.02664576802507837, 'mean_word_length': 3.885204081632653, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '474217', 'license': 'MIT', 'n_tokens_mistral': 630, 'n_tokens_neox': 608, 'n_words': 225, 'path': '12-errors_and_exception-handling.ipynb', 'repo_name': 'himanshu238/Python-Bootcamp', 'size': '1914'}