
Exception Handling Video
Exception Handling Video
null
Content
1.1 -> hello my name is Christopher today I'll
be talking about exception handling
5.79 -> now what exception handling is is
basically a way for your code to
10.59 -> handle errors another way to look at except
exception handling will be to see it as
17.49 -> error handling since exceptions and
errors are pretty much the same thing
22.67 -> now the reason that we use exception
handling it is so that when you run your
28.05 -> code it doesn't crash due to an error
most of the time due to user input
35.66 -> but instead it prints out a message that
you have already written nowthe
46.17 -> code that I'll be talking about today
that uses them that use exception
49.829 -> handling will be this code that I use
for my final project which is a
53.52 -> player driver that I will be using a
try-catch block today for exception
62.67 -> handling and there's two here so let's
get into it
68.15 -> so first let me give a brief description
of this code does it it creates a player
73.17 -> and then I asks the user for multiple
inputs for the different parameters
82.08 -> the player
object will need and then then inputs
88.049 -> them then there's also this printWriter
which requires this IOException
93.57 -> catch block here today I'm
going to focus on this input mismatch
99.36 -> exception catch block all right so
when you're run the code you'd be prompt
108.6 -> to all these things and then if at any
point we encounter input mismatch error
114.21 -> which is like for example you can put a
string where's was inputted integer or
118.979 -> you run into this catch
122.79 -> block here and you'll be prompted with
this message telling you that you
128.52 -> inputed a non numerical value for one of
the following because most of the time
132.18 -> it's going to be that you inputted a srting where you needed to input an integer or double
138.87 -> so let me run thisto give you a better idea of how it
works so let's just create one player it
144.03 -> right here where it tells you to create a player so it can be simpler now enter the name of
148.769 -> the player let's say John Smith and enter
in the position lets say first baseman
160.14 -> first base then here let's create the error here alright so enter the age of the
165.84 -> player you're expected to enter an
integer here but let's say we enter some
172.889 -> random letters on accident just to help
you visualize so we enter letters
179.19 -> instead of integers and this is what we get
the build still runs but now you get
184.709 -> prompted with this message saying that
you have inputted in a non numerical value
187.95 -> for one of the following age, yard40, atBats, or
successful hits because these are pretty
194.4 -> much the only places you'll be able to
get an error from input mismatch
199.5 -> where you're prompted above so
now you'll see as it's usually supposed
206.31 -> to print to this file but instead it
doesn't print at all since we
213.69 -> encountered an error and it was cancelled out by the try catch block so now
219.03 -> nothing printed so now let's show you
how it would look when it's successful
223.459 -> so I'm just going to put a bunch of
random information just to show you
231.23 -> input numbers here numbers
here now this time we had to build
237.209 -> successful since everything we inputted
match what it was supposed to now let's
242.909 -> show you how its supposed to look when it
prints and this it how it looks when it prints
246.959 -> and prints out all this so by using this
exception handling it causes a code not
257.519 -> to crash but instead it it tells
the user where made an error so they can
264.3 -> fix it on their next go-around
so that is exception handling
Source: https://www.youtube.com/watch?v=F5kMbvQdTio