Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Python 10 questions

Exception Handling & Debugging

Implement try-except-finally blocks, handle custom errors, raise assertions, and debug logic flows in Python.

More Python
Interview questions 1–10 of 10
1

How does try/except/else/finally work in Python?

BlockRuns whentryContains code that might raise an exceptionexceptOnly if an exception occurs in tryelseOnly i...

Read answer →
2

How do you catch multiple exceptions in Python?

# Catching multiple exception types with one handler try: value = int(input('Enter a number: ')) resul...

Read answer →
3

How do you create and raise custom exceptions in Python?

Custom exceptions are created by subclassing Exception (or a more specific built-in exception), allowing you t...

Read answer →
4

What is exception chaining and what does 'raise ... from ...' do?

Exception chaining preserves the original exception's context when raising a new one in response to it, making...

Read answer →
5

What is the difference between Exception and BaseException in Python?

BaseException is the root of Python's exception hierarchy. Exception is a subclass of it that covers 'normal'...

Read answer →
6

How do context managers (the 'with' statement) relate to exception handling?

The 'with' statement guarantees cleanup code runs even if an exception occurs inside the block, using a contex...

Read answer →
7

How do you use assertions for debugging in Python, and when should you avoid them?

assert statements check that a condition is true, raising an AssertionError if not. They're meant for catching...

Read answer →
8

How does Python's traceback help you debug errors?

A traceback shows the exact sequence of function calls that led to an unhandled exception, read from top (wher...

Read answer →
9

What is the difference between logging and using print() for debugging?

Aspectprint()loggingSeverity levelsNo distinctionDEBUG, INFO, WARNING, ERROR, CRITICALOutput controlAlways pri...

Read answer →
10

What is the difference between raise, raise Exception, and re-raising a caught exception with bare raise?

UsageEffectraise SomeError('msg')Raises a new exception with a fresh traceback starting hereraise (bare, insid...

Read answer →