Defining an Exception

Create an empty exception named StringTooLongException. Remember that all exceptions must be derived from an Exception class.

def string_check(a_string):
    if len(a_string) > 10:
        raise StringTooLongException
    else:
        return a_string
import unittest

class TestExceptions(unittest.TestCase):
    
    def test_custom_string_exception(self):

        def string_length(a_string):
            if len(a_string) > 7:
                raise StringTooLongException
            else:
                pass
        
        self.assertRaises(StringTooLongException, string_length, '001100010010011110100001101101110011')