nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound

AI-powered interview preparation platform. Practice with curated questions, mock interviews, and personalized learning paths to crack your dream tech interview.

Quick Links

  • Technologies
  • Mock Interviews
  • Saved Questions
  • Pricing

Company

  • About Us
  • Contact Us

Legal

  • Privacy Policy
  • Terms of Use

© 2026 nextRound. All rights reserved.

Questions
3 of 8
1What does exception chaining (raise X from Y) accomplish, and how does it aid debugging?
2Your program is consuming increasing memory over time (a suspected memory leak) despite Python's garbage collector. How would you investigate this?
3What is the difference between except Exception and a bare except:? Why is the bare form discouraged?
4What is the purpose of the else and finally clauses in a try block?
5A production script fails intermittently with a RecursionError. How would you diagnose and fix it?
6What tools would you use to profile a slow Python function, and how do you interpret the output?
7How would you design a custom exception hierarchy for an application?
8How would you use Python's logging module effectively instead of print statements for debugging production code?
PythonPython
Basics
Control Flow and Functions
Data Structures
Comprehensions & Functional Programming
Iterators, Generators & Decorators
Object-Oriented Programming
Exception Handling & Debugging
Concurrency & Parallelism
Performance & Optimization
Testing
Security
Modules, Packaging & Environment
Type Hinting & Modern Python
System Design & Architecture with Python
Best Practices & Design Patterns
Edge Cases & Tricky Interview Questions
03 / 08

What is the difference between except Exception and a bare except:? Why is the bare form discouraged?

Difficulty: 3/10
Exception Hierarchy, Bare Except, Error Handling

except Exception catches application errors; bare except catches everything including SystemExit and KeyboardInterrupt

In Python 3, every exception derives from BaseException. SystemExit, KeyboardInterrupt, and GeneratorExit are direct subclasses of BaseException, not Exception. except Exception catches only the Exception subtree, so Ctrl+C and sys.exit() still work as expected. A bare except: is equivalent to except BaseException: and will swallow KeyboardInterrupt, SystemExit, and GeneratorExit, which breaks shutdown signals and makes a process unkillable with Ctrl+C. That is the actual reason it is discouraged: it is not about style, it is about keeping the control-flow exceptions that are not application errors out of your handler.

  1. 1

    BaseException: SystemExit, KeyboardInterrupt, GeneratorExit, and Exception.

  2. 2

    Exception: the branch for ordinary application and library errors. This is what you almost always want.

  3. 3

    Catch the narrowest exception you can handle. Catching something you cannot recover from just hides the failure.

  4. 4

    Use bare except only in rare cleanup code that must run for any exit reason, and immediately re-raise with raise.

  5. 5

    Common mistake: writing except: pass during debugging, which swallows the error and makes root cause invisible.

  6. 6

    Common mistake: assuming except Exception catches everything. It does not catch KeyboardInterrupt or SystemExit.

  7. 7

    Version note: Python 2 allowed raising old-style strings and had a different hierarchy in some edge cases; the modern hierarchy described here is Python 3.

javascript

Scenario Questions

0-2 years experience

  1. 1Why does Ctrl+C stop working after someone added a bare except around a loop?
  2. 2Which base class should you almost always catch?

2-5 years experience

  1. 1A service hangs instead of shutting down on SIGTERM. How do you find the bare except that is swallowing SystemExit?
  2. 2You need to log every error but never mask Ctrl+C. How do you structure the handler?

5-8 years experience

  1. 1You are reviewing a codebase with dozens of bare excepts. How do you prioritize which to fix and what replacement patterns do you apply?
  2. 2You maintain a library and your users complain that KeyboardInterrupt is swallowed by one of your functions. How do you fix it without breaking callers?

8+ years experience

  1. 1Design a top-level error boundary for a long-running service that catches application errors, logs them, and still honors shutdown signals and cancellation.
  2. 2Explain how BaseException interacts with async cancellation, GeneratorExit, and context managers, and how to write boundaries that do not break them.

Follow-up Questions

  • What exceptions live outside the Exception subtree and why does that matter?
  • When is it acceptable to write a bare except and what must you do inside it?
Sharethis question

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.