text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
let them try to catch that exception as | 3,325.24 | 6.04 |
needed so let me go back to vs code here | 3,328.599 | 5.72 |
and propose that if the user passes in | 3,331.28 | 5.279 |
an invalid name it's just empty so | 3,334.319 | 4.321 |
there's not a name well what I really | 3,336.559 | 5.201 |
want to do is this I want to raise a | 3,338.64 | 5.6 |
value error and we've seen the value | 3,341.76 | 4.88 |
errors before we've created value errors | 3,344.24 | 4.319 |
accidentally before and generally you | 3,346.64 | 4.199 |
and I have try to catch them if they | 3,348.559 | 4.48 |
happen well the flip side of this | 3,350.839 | 4.161 |
feature of exceptions in a language like | 3,353.039 | 3.76 |
python is that you the programmer can | 3,355 | 3.64 |
also raise exceptions when something | 3,356.799 | 4.32 |
exceptional happens and you can even be | 3,358.64 | 4.04 |
more precise you don't have to raise a | 3,361.119 | 3.2 |
generic value error and let the | 3,362.68 | 3.52 |
programmer figure out what went wrong | 3,364.319 | 4.04 |
you can treat value error and all | 3,366.2 | 4.32 |
exceptions in Python like functions and | 3,368.359 | 4.801 |
actually pass to them a an explanatory | 3,370.52 | 5.24 |
message like quote unquote missing name | 3,373.16 | 4.04 |
so that at least the programmer when | 3,375.76 | 2.88 |
they encounter this error knows oh I | 3,377.2 | 3.72 |
messed up I didn't make sure that the | 3,378.64 | 5.52 |
user has a name and now what do you want | 3,380.92 | 5.36 |
to do instead well now if you're the | 3,384.16 | 4.04 |
programmer you could do something like | 3,386.28 | 6.039 |
this you could try to create a student | 3,388.2 | 7.359 |
except if there's a value error then you | 3,392.319 | 4.961 |
could handle it in some way and I'm | 3,395.559 | 3.8 |
going to wave my hand with a dot dot dot | 3,397.28 | 3.88 |
at how you would handle it but you would | 3,399.359 | 3.96 |
handle it using try and accept just like | 3,401.16 | 4.439 |
we have in the past and that would allow | 3,403.319 | 4.321 |
you the programmer to try to create the | 3,405.599 | 3.841 |
student but if something goes wrong okay | 3,407.64 | 4.84 |
okay I'll handle it nonetheless so | 3,409.44 | 4.84 |
what's new here again is this raise | 3,412.48 | 4.319 |
keyword that just lets you and I | 3,414.28 | 4.92 |
actually raise our own exceptions to | 3,416.799 | 4.32 |
Signal these errors well let me go back | 3,419.2 | 4.119 |
to my code here and I'm just going to go | 3,421.119 | 4.48 |
ahead and not bother trying or catching | 3,423.319 | 4.24 |
this error for now we'll just focus on | 3,425.599 | 4.041 |
raising it and assume that from our week | 3,427.559 | 4.24 |
on exceptions you could add try and | 3,429.64 | 4.6 |
accept as needed in places let me go | 3,431.799 | 4.401 |
back to the code here and propose that | 3,434.24 | 3.92 |
something else could go wrong with house | 3,436.2 | 3.839 |
right if there is a name we're good but | 3,438.16 | 3.8 |
if we're given a house but it's invalid | 3,440.039 | 3.961 |
we should probably raise an exception | 3,441.96 | 4.48 |
for that too so what if we do this if | 3,444 | 5.839 |
house is not in the list containing | 3,446.44 | 6.52 |
Gryffindor quote unquote uh Hufflepuff | 3,449.839 | 6.081 |
quote unquote uh let's see Ravenclaw | 3,452.96 | 6.24 |
quote unquote or uh Slytherin quote | 3,455.92 | 6.08 |
unquote then with my colon let's raise | 3,459.2 | 4.52 |
another type of value error but rather | 3,462 | 3.72 |
than raise a generic value error let's | 3,463.72 | 4.28 |
pass in an argument quote unquote | 3,465.72 | 6.04 |
invalid house and so here we now see a | 3,468 | 6.039 |
capability that we can do with classes | 3,471.76 | 4.839 |
that we can't with dictionaries if you | 3,474.039 | 5.601 |
add an attribute to a dictionary a key | 3,476.599 | 5.041 |
to a dictionary it's going in no matter | 3,479.64 | 4.32 |
what even if the name is empty even if | 3,481.64 | 4.28 |
the house is a completely random string | 3,483.96 | 3.399 |
of text that's not one of these four | 3,485.92 | 3.52 |
houses it's going into that dictionary | 3,487.359 | 4.401 |
but with the class and by way of this | 3,489.44 | 5.44 |
init method you and I can now control | 3,491.76 | 5.44 |
exactly what's going to be installed if | 3,494.88 | 4.28 |
you will inside of this object you have | 3,497.2 | 4.399 |
a little more control now over | 3,499.16 | 4.639 |
correctness and so now let me go ahead | 3,501.599 | 4.601 |
and uh scroll back down to my terminal | 3,503.799 | 4.681 |
window and clear it let me run python of | 3,506.2 | 4.359 |
studenty let me type in something like | 3,508.48 | 4.92 |
Harry let me type in Gryffindor enter | 3,510.559 | 4.28 |
and we see that indeed Harry is from | 3,513.4 | 3.84 |
Gryffindor what if I made a mistake | 3,514.839 | 4.52 |
though what if I ran python of student. | 3,517.24 | 4.079 |
and typed Harry is the name but I this | 3,519.359 | 4.801 |
time typed in number four Private Drive | 3,521.319 | 4.52 |
which is where he grew up instead of his | 3,524.16 | 4.04 |
proper Hogwarts house let me hit enter | 3,525.839 | 5.641 |
now and now you see a value error but | 3,528.2 | 5.359 |
this isn't one that python generated for | 3,531.48 | 5.04 |
us per se I rais this error and | 3,533.559 | 4.681 |
therefore if I went in and wrote more | 3,536.52 | 3.4 |
code in my get student function I could | 3,538.24 | 5.359 |
also catch this error with our usual try | 3,539.92 | 5.8 |
except syntax so all we have now is not | 3,543.599 | 4.681 |
just classes in our toolkit but even | 3,545.72 | 5.04 |
more Powers when it comes to exceptions | 3,548.28 | 4.64 |
and not just catching them ourselves but | 3,550.76 | 5.559 |
raising them ourselves too any questions | 3,552.92 | 4.879 |
now | 3,556.319 | 4.641 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.