Skip to content
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

Update 10-all-about-exceptions.md #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ weight: 1

Built-in exceptions and easy exception handling is one of the shining features of Python. Technically, errors that happen during parsing are called `SyntaxError`s - these will probably be the most common errors you see, and usually happen because of a mistake in whitespace, a syntax misunderstanding, or a simple typo.

Even if the syntax is correct, errors can still occur when your program is run. We call these Exceptions, and there a many different types (this is a good thing, because the more specifically we know what went wrong, the better we can handle it).
Even if the syntax is correct, errors can still occur when your program is run. We call these Exceptions, and there are many different types (this is a good thing, because the more specifically we know what went wrong, the better we can handle it).

An un-handled exception is fatal: it will print debugging information (called a traceback), stop the interpreter, and exit your program. However, once you learn to handle Exceptions, you can cover your bases and write programs that are robust in the face of issues.

Expand Down Expand Up @@ -44,4 +44,4 @@ What if we want our program to stop, though? You may already be familiar with `c

You can also use `sys.exit()` from the built-in `sys` library. It's generally not a good idea to pepper `sys.exit()` around your code, as it makes it harder to control when your program exits, but this can be a handy function for controlling how and when your program exits. By default, `sys.exit()` with no parameters will exit with a `0` return code, which, by posix convention, signals success. You can pass an integer to `sys.exit()` if you'd like to exit with a non-zero return code (usually signaling some sort of failure condition). You can also pass a string to `sys.exit()`, which will get printed to the command line, along with a return code of `1`.

`sys.exit()` generates a `SystemExit` exception, which inherits from the master `BaseException` class, which makes it possible for clean-up handlers (such as `finally` statements) to run.
`sys.exit()` generates a `SystemExit` exception, which inherits from the master `BaseException` class, which makes it possible for clean-up handlers (such as `finally` statements) to run.