Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
35 views

Exceptions: Basic Types Checked Unchecked Exceptions Run Time Error

There are two main types of exceptions in Java: checked exceptions and unchecked exceptions. Checked exceptions must be caught using try/catch blocks, as they represent potential problems caused by user input or operations. Unchecked exceptions are divided into runtime exceptions and errors, and do not require catching. Runtime exceptions can often be avoided by programmers, while errors are outside the programmer's control.

Uploaded by

Vishal Iyer
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Exceptions: Basic Types Checked Unchecked Exceptions Run Time Error

There are two main types of exceptions in Java: checked exceptions and unchecked exceptions. Checked exceptions must be caught using try/catch blocks, as they represent potential problems caused by user input or operations. Unchecked exceptions are divided into runtime exceptions and errors, and do not require catching. Runtime exceptions can often be avoided by programmers, while errors are outside the programmer's control.

Uploaded by

Vishal Iyer
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Exceptions

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

Checked Exceptions
. 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. These exception are sub%ect to catch or speci y re&uirement. 'hich means either these should be included in try (catch or intently thrown

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 . These may be included in try catch * %a$a exception handlers can help to reco$er rom these type o exceptions.

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

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

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

You might also like