Print exception details
Write a Python program that prints the type, message and line of a caught exception. Step-by-step explanation, colour-coded code and real output.
Online Learning Platform
Free tutorials, solved practice problems and interview prep for QA and automation engineers: Python, Playwright, Selenium, SQL, Git and more.
Write a Python program that prints the type, message and line of a caught exception. Step-by-step explanation, colour-coded code and real output.
Write a Python program that keeps asking for a number until a valid one is entered. Step-by-step explanation, colour-coded code and real output.
Write a Python program that uses `assert` to check a condition and handles the AssertionError. Step-by-step explanation, colour-coded code and real output.
Write a Python program that retries an unreliable operation up to 3 times. Step-by-step explanation, colour-coded code and real output.
Write a Python program that opens a file and handles the case where it does not exist. Step-by-step explanation, colour-coded code and real output.
Write a Python program that converts a low-level error into a clearer one and keeps the cause. Step-by-step explanation, colour-coded code and real output.
Write a Python program that logs an error and then re-raises it to the caller. Step-by-step explanation, colour-coded code and real output.
Write a Python program with a custom `InsufficientBalanceError`. Step-by-step explanation, colour-coded code and real output.
Write a Python function that raises ValueError for an invalid age. Step-by-step explanation, colour-coded code and real output.
Write a Python program that shows `finally` always runs. Step-by-step explanation, colour-coded code and real output.
Write a Python program that uses `else` to run code only when no exception occurred. Step-by-step explanation, colour-coded code and real output.
Write a Python program that catches ValueError and TypeError in one except block. Step-by-step explanation, colour-coded code and real output.
Take free timed mock tests with answers and explanations.