Exceptions

Basic types 1) Checked 2) Unchecked Exceptions a) Run time b) Error

'hich means either these should be included in try (catch or intently thrown . These exception are sub%ect to catch or speci y re&uirement. These are exceptional conditions which normally are due to user o a pro!ram because o a wron! input or operation "or example #supposin! user !i$es a ile name which does not exist.Checked Exceptions • .

These may be included in try catch * %a$a exception handlers can help to reco$er rom these type o exceptions.Unchecked Exceptions • These are o two types a) Run time b) Error • These are not sub%ect to catch or speci y re&uirement • Run time # These can normally be a$oided by a pro!rammer these may be caused by lo!ical error in pro!ram or some un unexpected run time error which has not been $isuali)ed by pro!rammer . .

Unchecked Exceptions • Errors # These are not in control o pro!rammer or example a ile cannot be opened because o some hardware problem .

. catch -40Exception e) + /01E 1E//23E 0R 2CT40.ot"oundException e) + /01E 1E//23E 0R 2CT40. .• try + (( CODE WHICH MAY CAYSE EXCEPTIONS .. inally + some action or messa!e. catch -"ile.

Try and catch • There can be one or more than one catch • "inally block is not necessary • Catch should always ha$e ar!ument o exception or its sub class • .

Checked exceptions • "or code which anticipate that a checked exception may occur must be contained in try catch • "or example br.readline-)5 4 you purposely want to a$oid try and cache or checked exception use key word throws .

.static /trin! read"irst6ine"rom"ile-/trin! path) throws 40Exception • + • Code without try an catch • .

Exception class hierarchy .

Sign up to vote on this title
UsefulNot useful