3- Types of Exceptions

Jun 18, 2026 03:34 · 3:40 · English · Whisper Turbo · 2 speakers
This transcript expires in 21 mazuva. Upgrade for permanent storage →
Kuratidza chete
0:03
S… Speaker 1 (3- Types of Exceptions)
In Java,
0:04
S… Speaker 2 (3- Types of Exceptions)
we have three types of exceptions.
0:05
S… Speaker 1 (3- Types of Exceptions)
Checked exceptions,
0:07
S… Speaker 1 (3- Types of Exceptions)
unchecked exceptions,
0:08
S… Speaker 2 (3- Types of Exceptions)
also called runtime exceptions,
0:10
S… Speaker 2 (3- Types of Exceptions)
and errors.
0:11
S… Speaker 2 (3- Types of Exceptions)
A lot of people new to Java find this confusing,
0:14
S… Speaker 2 (3- Types of Exceptions)
so let me make it super simple for you.
0:16
S… Speaker 2 (3- Types of Exceptions)
Checked exceptions are exceptions that we developer should anticipate and
0:20
S… Speaker 2 (3- Types of Exceptions)
handle properly.
0:21
S… Speaker 1 (3- Types of Exceptions)
For example,
0:22
S… Speaker 2 (3- Types of Exceptions)
let's say we want to read data from a file.
0:24
S… Speaker 2 (3- Types of Exceptions)
What if the file doesn't exist?
0:26
S… Speaker 2 (3- Types of Exceptions)
Maybe it got deleted just before we tried to open it for reading.
0:29
S… Speaker 2 (3- Types of Exceptions)
Good developers always anticipate and handle these edge cases.
0:33
S… Speaker 2 (3- Types of Exceptions)
So instead of letting the runtime terminate our program,
0:36
S… Speaker 2 (3- Types of Exceptions)
we would better display a friendly message to the user saying,
0:39
S… Speaker 1 (3- Types of Exceptions)
hey,
0:39
S… Speaker 2 (3- Types of Exceptions)
that file doesn't exist.
0:41
S… Speaker 1 (3- Types of Exceptions)
Now,
0:42
S… Speaker 2 (3- Types of Exceptions)
the good news is that the Java compiler enforces us to handle these errors.
0:46
S… Speaker 2 (3- Types of Exceptions)
That is why they're called checked exceptions because they get checked at compile
0:50
S… Speaker 1 (3- Types of Exceptions)
time. Let me show you.
0:52
S… Speaker 2 (3- Types of Exceptions)
Let's create a new file reader for reading data from a file so reader
0:57
S… Speaker 2 (3- Types of Exceptions)
equals new file reader Let's say
1:01
S… Speaker 2 (3- Types of Exceptions)
file that txt now look at this read underline the Java
1:05
S… Speaker 2 (3- Types of Exceptions)
compiler knows that the constructor of the file reader will throw an exception
1:09
S… Speaker 2 (3- Types of Exceptions)
if the file doesn't exist So it's telling us hey you haven't handled
1:13
S… Speaker 2 (3- Types of Exceptions)
this exception file not found exception.
1:16
S… Speaker 2 (3- Types of Exceptions)
This is an example of a checked exception
1:18
S… Speaker 2 (3- Types of Exceptions)
So checked exceptions are exceptions that we should anticipate and recover from
1:23
S… Speaker 2 (3- Types of Exceptions)
and that is why they're called checked exceptions because the Java compiler checks
1:27
S… Speaker 2 (3- Types of Exceptions)
them at compile time.
1:28
S… Speaker 2 (3- Types of Exceptions)
Now the second type of exception is called unchecked exception or runtime
1:32
S… Speaker 1 (3- Types of Exceptions)
exception.
1:33
S… Speaker 2 (3- Types of Exceptions)
As the name implies,
1:34
S… Speaker 2 (3- Types of Exceptions)
these exceptions are not checked by the compiler at compile time.
1:38
S… Speaker 2 (3- Types of Exceptions)
They occur because of programming errors.
1:40
S… Speaker 2 (3- Types of Exceptions)
Null pointer exception is an example of a runtime exception.
1:44
S… Speaker 2 (3- Types of Exceptions)
In the last video,
1:45
S… Speaker 2 (3- Types of Exceptions)
we shouldn't have passed null to the say hello method.
1:48
S… Speaker 2 (3- Types of Exceptions)
This is a programming error.
1:49
S… Speaker 1 (3- Types of Exceptions)
So unlike checked exceptions,
1:51
S… Speaker 2 (3- Types of Exceptions)
we don't want to anticipate and recover by displaying a friendly message
1:55
S… Speaker 1 (3- Types of Exceptions)
like, hey,
1:56
S… Speaker 2 (3- Types of Exceptions)
we made a mistake and try to use an object reference with the null value.
2:00
S… Speaker 1 (3- Types of Exceptions)
Doesn't make sense.
2:01
S… Speaker 2 (3- Types of Exceptions)
Instead, we should prevent exceptions like this from happening in the first place.
2:04
S… Speaker 2 (3- Types of Exceptions)
How can we do that?
2:06
S… Speaker 2 (3- Types of Exceptions)
By good coding practices and testing,
2:08
S… Speaker 2 (3- Types of Exceptions)
a lot of testing,
2:09
S… Speaker 2 (3- Types of Exceptions)
preferably automated testing.
2:11
S… Speaker 2 (3- Types of Exceptions)
That's a topic for an entirely different course.
2:13
S… Speaker 1 (3- Types of Exceptions)
Now,
2:14
S… Speaker 2 (3- Types of Exceptions)
other examples of runtime exceptions are arithmetic exception.
2:18
S… Speaker 2 (3- Types of Exceptions)
This gets thrown if you try to divide a value by zero.
2:21
S… Speaker 2 (3- Types of Exceptions)
You also have illegal argument exception for indicating that
2:25
S… Speaker 2 (3- Types of Exceptions)
the argument we passed to a method was not accepted.
2:28
S… Speaker 2 (3- Types of Exceptions)
Again, this is a programming mistake,
2:30
S… Speaker 2 (3- Types of Exceptions)
not a kind of error that we should anticipate and validate.
2:34
S… Speaker 2 (3- Types of Exceptions)
Another runtime exception you may see is the index out of bounds exception,
2:38
S… Speaker 2 (3- Types of Exceptions)
which occurs if we try to access an element in an array or a string
2:42
S… Speaker 2 (3- Types of Exceptions)
or a list using an invalid index.
2:44
S… Speaker 1 (3- Types of Exceptions)
For example,
2:45
S… Speaker 2 (3- Types of Exceptions)
we have five elements in an array,
2:47
S… Speaker 2 (3- Types of Exceptions)
but we try to access the 10th element.
2:49
S… Speaker 2 (3- Types of Exceptions)
Another popular runtime exception is illegal set exception,
2:53
S… Speaker 2 (3- Types of Exceptions)
which gets thrown if we try to call a method,
2:55
S… Speaker 2 (3- Types of Exceptions)
but the underlying object is not in the right state.
2:59
S… Speaker 2 (3- Types of Exceptions)
So these are runtime exceptions.
3:00
S… Speaker 2 (3- Types of Exceptions)
The third type of exception we have in Java is an error which indicates
3:04
S… Speaker 2 (3- Types of Exceptions)
an error external to our application.
3:07
S… Speaker 2 (3- Types of Exceptions)
Examples are stack overflow error or out of memory error.
3:11
S… Speaker 2 (3- Types of Exceptions)
So if the Java virtual machine runs out of memory,
3:14
S… Speaker 2 (3- Types of Exceptions)
there's nothing we can do about it.
3:15
S… Speaker 1 (3- Types of Exceptions)
So just like runtime exceptions,
3:17
S… Speaker 2 (3- Types of Exceptions)
we should let the application crash rather than display a friendly message to
3:21
S… Speaker 1 (3- Types of Exceptions)
the user.
3:21
S… Speaker 2 (3- Types of Exceptions)
We should try to identify the source of these errors.
3:24
S… Speaker 2 (3- Types of Exceptions)
These errors can happen because of programming errors like an infinite recursion
3:28
S… Speaker 2 (3- Types of Exceptions)
or for reasons outside of our application like a problem in the Java virtual
3:33
S… Speaker 1 (3- Types of Exceptions)
machine itself.
3:33
S… Speaker 1 (3- Types of Exceptions)
Next,
3:34
S… Speaker 2 (3- Types of Exceptions)
we're going to look at the hierarchy of exception classes in Java.

This transcript was generated by AI (automatic speech recognition). May contain errors — verify against the original audio for critical use. AI policy

❤️ Love STT.ai? Chii shamwari dzako!
_Zvinyorwa
Tinya Summarize kuti uwane AI ongororo yechinyorwa ichi.
Kuongorora...
Ask AI About This Transcript
Kubvunza chero chinhu nezve iyi transcript - AI ichawana zvinyorwa zvinokosha uye mashoko.