Exceptions Testing

Question

ADDQUESTION

Solution

from urllib.error import URLError, HTTPError
from io import StringIO

print(isinstance(URLError("foo"), HTTPError))
print(isinstance(HTTPError("foo", "bar", "baz", "zap", StringIO()), URLError))

try:
    raise HTTPError("foo", "bar", "baz", "zap", StringIO())
except URLError:
    print("caught this exception")
else:
    print("this exception escaped.")