Skip to content
Snippets Groups Projects
Commit f48858c9 authored by Ralf Mueller's avatar Ralf Mueller :fishing_pole_and_fish:
Browse files

add examples for errors with/without messages

parent 288ab074
No related branches found
No related tags found
No related merge requests found
Pipeline #11298 passed
# How to work with broken programs
Example: NCL_color_1.py
Error:
# Debugging: How to work with broken programs
What is the Problem? Why debugging? Everything works, right?
## No! Every real world program has errors. Amen
Two options:
- easy: the program crashes and shows error messages
- hard: the program seem to work properly, but the results are unexpected
### Example (easy)
Let's take an example of geocat, because they offer so many nice plots: [NCL_color_1.py](./scripts/NCL_color_1.py)
There should be some nice errors in it, too ;-)
Lessions:
- Understand your environment and its limitations
- Read error messages and warning. They are your best friends (most of the time)
An common example of a message hard to understand:
```python
print("a = {0}".format(55)
```
throws this:
```shell
SyntaxError: unexpected EOF while parsing
```
Keep it in mind
### Example (hard)
```python
import sys
def sum(a,b):
return a+b
if __name__ == "__main__":
# first some tests
print("2 = {0}".format(sum(1,1)))
print("5 = {0}".format(sum(1,4)))
print("4 = {0}".format(sum(2,2)))
# now some user given numbers
a = sys.argv[1]
b = sys.argv[2]
print("a = {0}".format(a))
print("b = {0}".format(b))
print("sum = {0}".format(sum(a,b)))
```
### Example (harder)
What should be the result?
```python
0.3 == 0.1 + 0.2
True or False #???
```
It's quite obvious, isn't it? Try it!
#
Problem: What to do, when the error message is crap
# printf debugger .. or print
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment