Professional Documents
Culture Documents
Ch10exaption Handling in Java
Ch10exaption Handling in Java
~ -- - - - "= - - '='
• Syntax error
• Mismatch of bracket
Run - time errors
t If there are no syntax errors in the source code then the
program will compile successf ully and will get a9 file.
t However this does no• guarantee that the program will
execute as per our expectations.
Example :
t In the program, we have created an array citylist[).
tThat contains name of four different cities.
t We are trying to display the contents of element of citylist
array that does not exist.
[TI
e Chapter 1 Creating HTM X
or not.
[TI
Exception Handling
t An exception is an error condition.
t Java uses 3 keywords to writeari'exception handler :
(1) try
-
: Contains the code to one or more exceptions.
particula~ e.
IT]
e How to download kompo X
try block
IHry statement contains a block of statements within the
~r~ o)
t A try block may give rise to one or more exceptions.
t Syntax of try block is : try { \ ~
t After try statement, there has to be either a catch block or
a finally block.
IT]
catch block
tcatch block must immediately follow the try block.
CT]
e Windows 11 New Featur X
fi~ I
t finally block is generally used to ~ t the end of
executing a try block.
Example :