Why: Python Debugging, Stack Trace, Exception Handling, Try / Except & Raise? (W/ Mnemonics)

preview_player
Показать описание
Get The Full “Learn Python 🐍” Online Course:

The following video is from an online educational course produced by Mnemonic Academy that teaches the basics of Python programming using mnemonics, metaphors and the science of learning titled “Learn Python: Like a Bee Student”, taught by instructor Dylan Jorgensen

What is a bug?
- A software bug is an error, flaw, failure or fault in a computer program or system that causes it to produce an incorrect or unexpected result, or to behave in unintended ways.

Bugs vs. Features?
- Bugs can come in shades of grey if you don’t clearly define the functionality you want to achieve. -
Sometimes bugs become features.

What is debugging?
- Debugging is the processing of smoothing out the bugs, once you have a clear definition of the functionality you want.
- Debugging can be as simple as a print command that prints variables at certain points of a program. Or as complicated as introducing new complex debug code to test for subtle changes between your expected outputs and the true outputs.

What is a stack trace?
- A stack trace is a report that reports at certain points in time during the execution of a program.
- A stack trace is a list of the method calls that the application was in the middle of when an error occurred. (AKA: Exception was thrown.)

How to Read the Stack Trace?
- Not every bug will have a stack trace, but many do and if they do then this means the bug is not on the surface but instead wrapped up deeper down.
- Deeper down could mean the order the code is compiled. Or in a deeper scope like a function, or even in open sources modules imported.
- So instead of starting at the top of our code we just start with our topmost method call and often this will get our attention close enough to the problem we can work through the rest.

What are exceptions?
- Imagine if somebody passed in a string argument when your function only works with integers. Exception handling is how you deal with it.

What is the difference between a syntax error and an exception?
- Syntax errors, also known as parsing error. These are syntax problems and I think of them as similar to misspelling.
- Even if a statement or expression is syntactically correct, it may cause an error when an attempt is made to execute it.

What’s exception handling?
- Exception handling is about making sure that you have variables that don't break your code in a way that is similar to our conditional section before.
- Exception handling is the process of responding to an unwanted actions during either compile time or runtime.

What do the keywords try and except do?
- Python gives us some conditional keywords to help find where our code goes wrong
- First, the statements between the try and except keywords are executed. Then if no exception occurs, the except clause is skipped and execution of the try statement is finished.
- If an exception occurs during execution the rest of the clause is skipped. Then if its type matches the exception named after the except keyword, the except clause is executed, and then execution continues after the try statement.

What does the keyword raise do?
- Raise is a way to override the default exceptions in the way we want and display the information we want for the user.
- Raise allows us to define our own type of exception errors.

What does the keyword finally do?
- We can use the finally statement to ensure that a block of code is closed at the end of the file even if there is an exception that causes the interpreter to break.
- A time when you might want to do this is when you need to close out an open file at the very end of your program no matter what.

Is there a way to group errors into runtime and compile time?
- Error can be grouped into two different groups, one for run time and another for compile time.
Compile time errors happen when we feed a bunch of text to the compiler to convert it to machine code.

Interested in Learning More About Online Courses That Teach Using Mnemonics, Metaphors and the Science of Learning?

Checkout All Our Mnemonic Academy 🐝 Online Courses:

Subscribe To Our Mnemonic Academy 🐝 YouTube Channel:

Like Our Mnemonic Academy 🐝 Facebook Page:
Рекомендации по теме
Комментарии
Автор

show some codes, that would be better

Ddt-oe
visit shbcf.ru