Intro to Errors Flashcards

1
Q

Error

A

When a program does unexpected things

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Crash

A

When a program comes to a halt because of an error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Syntax Error

A

An error caused by incorrect syntax that Python cannot interpret

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Runtime Error

A

An error raised during runtime

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Logical Error

A

An error caused by incorrect logic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What could cause a Syntax error?

A

Syntax errors are often caused by things such as:

missing a keyword
missing a colon
missing the end of a brace, like ), }, ], etc
misspelling something
accessing a list or dictionary with the wrong syntax
unmatching indentation levels
mixed-use of tabs or spaces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What could cause a Runtime Error?

A

A runtime error is a kind of error that occurs while our program is already running.

There are actually plenty of actions that Python programs can’t do:

dividing by zero
performing an operation on incompatible types
using an identifier which has not been defined
accessing a list element, dictionary value or object attribute which doesn’t exist
trying to access a file which doesn’t exist

When our Python program is running, and it tries to do one of those actions, Python will raise a runtime error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What could cause a logical error?

A

A logical error is a kind of error that occurs when a program produces an incorrect result or outcome.

For example, if we write a Python program that should count the number of letters in the string “Grace Hopper”, and it produces the number 13 instead of the correct 12, and there are no syntax or runtime errors, then we have a logical error.

Logical errors can happen for an infinite number of reasons, but here are some common causes:

using the wrong variable name
incorrect indentation
not having the correct conditional checks off-by-one errors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Stack Trace (or “Trace Back” in Python)

A

A report of the active stack frames at a certain point in time during the execution of a program. Reports error messages and details about that error

Stacktrace is a list of what was running when it encountered the error with details about what happened.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Standard Stream Output

A

Let’s consider briefly where we see error messages, and in general all output. Right now, when we run Python code from the terminal, we see the output in the terminal. That’s because our computers and terminals have configured a standard stream for output , or an “output channel.” The output channel, or standard stream for output, for the terminal is the terminal itself by default.

We introduce this idea briefly because one day, the standard stream may change. :)In computer programming, standard streams are interconnected input and output communication channels[1] between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin), standard output (stdout) and standard error (stderr). Originally I/O happened via a physically connected system console (input via keyboard, output via monitor), but standard streams abstract this. When a command is executed via an interactive shell, the streams are typically connected to the text terminal on which the shell is running, but can be changed with redirection or a pipeline. More generally, a child process inherits the standard streams of its parent process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Traceback in Python

A

This module provides a standard interface to extract, format and print stack traces of Python programs. It exactly mimics the behavior of the Python interpreter when it prints a stack trace. This is useful when you want to print stack traces under program control, such as in a “wrapper” around the interpreter.

The module uses traceback objects — this is the object type that is stored in the sys.last_traceback variable and returned as the third item from sys.exc_info().

The module defines a variety of functions that you can look up in python library.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Finding The Good Stuff: How to Read Error Messages

A

When we come across errors, we should take notes of three things:

1) What is the description of the error
2) What is the name of the error
3) What is the line of code that caused the error, its file name and line number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly