Try-Catch-Raise-Error

Sat 17 May 2025

title: "Try Catch with Raise Error" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


def check_marks(mark):
    try:

        if(mark < 0):
            raise ValueError

        if(mark > 50):
            print('pass')
        else:
            print('fail')
    except ValueError:
        print('ValueError: Some value error')
    except TypeError:
        print('TypeError: Cannot convert into int')
check_marks(10)
fail
check_marks('10')
TypeError: Cannot convert into int
check_marks(-10)
ValueError: Some value error


Score: 5

Category: basics