Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions that inherit from BaseException should not be treated as Uncaught Exceptions #1590

Closed
danielniccoli opened this issue May 23, 2024 · 1 comment

Comments

@danielniccoli
Copy link

Before creating a new issue, please check the FAQ to see if your question is answered there.

Environment data

  • debugpy version: 1.8.1
  • OS and version: Windows 11
  • Python version: 3.11
  • Using VS Code or Visual Studio: VS Code

Actual behavior

exit(1) halts the debugging session due to an "uncaught exception"

grafik

grafik

Expected behavior

The program program should exit without the debugger halting.

Exceptions that inherit from exception.BaseException should not fall under the category of "uncaught exceptions", since they are "technically not an error"1.

exception.BaseException

The base class for all built-in exceptions. It is not meant to be directly inherited by user-defined classes (for that, use Exception).

https://docs.python.org/3/library/exceptions.html#BaseException

One of these exceptions is exception.SystemExit, which is called when calling exit(1).

exception SystemExit

This exception is raised by the sys.exit() function. It inherits from BaseException instead of Exception so that it is not accidentally caught by code that catches Exception. This allows the exception to properly propagate up and cause the interpreter to exit. When it is not handled, the Python interpreter exits; no stack traceback is printed.

https://docs.python.org/3/library/exceptions.html#SystemExit

There are only three other Exceptions that inherit from exception.BaseException, not counting exception.Exception, which does fall under the category of "Uncaught Exceptions":

BaseException
 ├── BaseExceptionGroup
 ├── GeneratorExit
 ├── KeyboardInterrupt
 ├── SystemExit
 └── Exception

https://docs.python.org/3/library/exceptions.html#exception-hierarchy

exception KeyboardInterrupt

Raised when the user hits the interrupt key (normally Control-C or Delete). During execution, a check for interrupts is made regularly. The exception inherits from BaseException so as to not be accidentally caught by code that catches Exception and thus prevent the interpreter from exiting.

exception GeneratorExit

Raised when a generator or coroutine is closed; see generator.close() and coroutine.close(). It directly inherits from BaseException instead of Exception since it is technically not an error.

Footnotes

  1. https://docs.python.org/3/library/exceptions.html#GeneratorExit

@danielniccoli danielniccoli changed the title Exceptions that inherit from BaseException should not be treated as Unhandled Exceptions Exceptions that inherit from BaseException should not be treated as Uncaught Exceptions May 23, 2024
@rchiodo
Copy link
Contributor

rchiodo commented May 23, 2024

Transferring to dicussions for up votes

@microsoft microsoft locked and limited conversation to collaborators May 23, 2024
@rchiodo rchiodo converted this issue into discussion #1591 May 23, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants