SlideShare a Scribd company logo
THROWING EXCEPTION AND
MULTIPLE CATCH BLOCK
Chapter 9.2:
Multiple catch Blocks
 A single try-catch statement can include multiple
catch blocks, one for each type of exception.
try {
. . .
age = Integer.parseInt(inputStr);
. . .
val = cal.get(id);
. . .
} catch (NumberFormatException e){
. . .
} catch (ArrayIndexOutOfBoundsException e){
. . .
}
Multiple catch Control Flow
 Only one catch{} block gets control (the first block that matches the type of the exception ).
 If no catch{} block matches the exception, none is picked (just as if there were no try{} block.)
Multiple catch Control Flow
 The most specific exception types should appear first in the structure, followed by
the more general exception types.
 A child class should appear before any of its ancestors. If class A is not an
ancestor or descendant of class B, then it doesn't matter which appears first.
 Eg. the following is wrong:
try {
...
} catch (Exception ex ) {
. . .
} catch (ArithmeticException ex ) {
. . .
}
Multiple catch Control Flow
 Question: Is this ok?:
try {
...
} catch (NumberFormatException ex ) {
. . .
} catch (ArithmeticException ex ) {
. . .
}
The finally Block
 There are situations where we need to take certain actions
regardless of whether an exception is thrown or not.
 We place statements that must be executed regardless of
exceptions in the finally block.
try {
// statements, some of which might
// throw an exception
} catch ( SomeExceptionType ex ) {
// statements to handle this
// type of exception
} catch ( AnotherExceptionType ex ) {
// statements to handle this
// type of exception
} finally {
// statements which will execute no matter
// how the try block was exited.
}
try-catch-finally Control
Flow

More Related Content

What's hot

exception handling in java
exception handling in javaexception handling in java
exception handling in java
Abinaya B
 
Exception
ExceptionException
17 exceptions
17   exceptions17   exceptions
17 exceptions
dhrubo kayal
 
Java - Exception Handling
Java - Exception HandlingJava - Exception Handling
Java - Exception Handling
Prabhdeep Singh
 
3.C#
3.C#3.C#
Exceptions
ExceptionsExceptions
Exceptions
DeepikaT13
 
Java Pitfalls and Good-to-Knows
Java Pitfalls and Good-to-KnowsJava Pitfalls and Good-to-Knows
Java Pitfalls and Good-to-Knows
Miquel Martin
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1
sotlsoc
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
saman Iftikhar
 
Built in exceptions
Built in exceptions Built in exceptions
Built in exceptions
TharuniDiddekunta
 
Exception hierarchy
Exception hierarchyException hierarchy
Exception hierarchy
Ashfaaq Mahroof
 
16 exception handling - i
16 exception handling - i16 exception handling - i
16 exception handling - i
Ravindra Rathore
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
Abinaya B
 
Exception handling
Exception handlingException handling
Exception handling
Shashwat Shriparv
 

What's hot (14)

exception handling in java
exception handling in javaexception handling in java
exception handling in java
 
Exception
ExceptionException
Exception
 
17 exceptions
17   exceptions17   exceptions
17 exceptions
 
Java - Exception Handling
Java - Exception HandlingJava - Exception Handling
Java - Exception Handling
 
3.C#
3.C#3.C#
3.C#
 
Exceptions
ExceptionsExceptions
Exceptions
 
Java Pitfalls and Good-to-Knows
Java Pitfalls and Good-to-KnowsJava Pitfalls and Good-to-Knows
Java Pitfalls and Good-to-Knows
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
 
Built in exceptions
Built in exceptions Built in exceptions
Built in exceptions
 
Exception hierarchy
Exception hierarchyException hierarchy
Exception hierarchy
 
16 exception handling - i
16 exception handling - i16 exception handling - i
16 exception handling - i
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
 
Exception handling
Exception handlingException handling
Exception handling
 

Similar to Chapter 9.2

Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
DevaKumari Vijay
 
Java unit3
Java unit3Java unit3
Java unit3
Abhishek Khune
 
1.12 Exception Handing.pptx
1.12 Exception Handing.pptx1.12 Exception Handing.pptx
1.12 Exception Handing.pptx
YashiUPADHYAY6
 
Exception Handling
Exception HandlingException Handling
Exception Handling
backdoor
 
L12.2 Exception handling.pdf
L12.2  Exception handling.pdfL12.2  Exception handling.pdf
L12.2 Exception handling.pdf
MaddalaSeshu
 
17 exception handling - ii
17 exception handling - ii17 exception handling - ii
17 exception handling - ii
Ravindra Rathore
 
Exception Handling
Exception HandlingException Handling
Exception Handling
Sunil OS
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Lovely Professional University
 
Java exceptions
Java exceptionsJava exceptions
Java exceptions
Pawan Kumar
 
Exception handling in java.pptx
Exception handling in java.pptxException handling in java.pptx
Exception handling in java.pptx
Nagaraju Pamarthi
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
Janki Shah
 
Exception handling
Exception handlingException handling
Exception handling
Abishek Purushothaman
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 
Exception handling
Exception handlingException handling
Exception handling
zindadili
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
yugandhar vadlamudi
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
Intro C# Book
 
Exception handling
Exception handlingException handling
Exception handling
Sandeep Rawat
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
EduclentMegasoftel
 
Exception Handling.pdf
Exception Handling.pdfException Handling.pdf
Exception Handling.pdf
lsdfjldskjf
 

Similar to Chapter 9.2 (20)

Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
 
Java unit3
Java unit3Java unit3
Java unit3
 
1.12 Exception Handing.pptx
1.12 Exception Handing.pptx1.12 Exception Handing.pptx
1.12 Exception Handing.pptx
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
L12.2 Exception handling.pdf
L12.2  Exception handling.pdfL12.2  Exception handling.pdf
L12.2 Exception handling.pdf
 
17 exception handling - ii
17 exception handling - ii17 exception handling - ii
17 exception handling - ii
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Java exceptions
Java exceptionsJava exceptions
Java exceptions
 
Exception handling in java.pptx
Exception handling in java.pptxException handling in java.pptx
Exception handling in java.pptx
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
 
Exception handling
Exception handlingException handling
Exception handling
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
Exception Handling.pdf
Exception Handling.pdfException Handling.pdf
Exception Handling.pdf
 

More from sotlsoc

Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 new
sotlsoc
 
Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 new
sotlsoc
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 new
sotlsoc
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 new
sotlsoc
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1
sotlsoc
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
sotlsoc
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4
sotlsoc
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3
sotlsoc
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
sotlsoc
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2
sotlsoc
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0
sotlsoc
 
Chapter 10.2
Chapter 10.2Chapter 10.2
Chapter 10.2
sotlsoc
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
sotlsoc
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0
sotlsoc
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0
sotlsoc
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3
sotlsoc
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4
sotlsoc
 
Chapter 8.1
Chapter 8.1Chapter 8.1
Chapter 8.1
sotlsoc
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0
sotlsoc
 
Chapter 8.3
Chapter 8.3Chapter 8.3
Chapter 8.3
sotlsoc
 

More from sotlsoc (20)

Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 new
 
Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 new
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 new
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 new
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0
 
Chapter 10.2
Chapter 10.2Chapter 10.2
Chapter 10.2
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4
 
Chapter 8.1
Chapter 8.1Chapter 8.1
Chapter 8.1
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0
 
Chapter 8.3
Chapter 8.3Chapter 8.3
Chapter 8.3
 

Recently uploaded

Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 

Recently uploaded (20)

Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 

Chapter 9.2

  • 1. THROWING EXCEPTION AND MULTIPLE CATCH BLOCK Chapter 9.2:
  • 2. Multiple catch Blocks  A single try-catch statement can include multiple catch blocks, one for each type of exception. try { . . . age = Integer.parseInt(inputStr); . . . val = cal.get(id); . . . } catch (NumberFormatException e){ . . . } catch (ArrayIndexOutOfBoundsException e){ . . . }
  • 3. Multiple catch Control Flow  Only one catch{} block gets control (the first block that matches the type of the exception ).  If no catch{} block matches the exception, none is picked (just as if there were no try{} block.)
  • 4. Multiple catch Control Flow  The most specific exception types should appear first in the structure, followed by the more general exception types.  A child class should appear before any of its ancestors. If class A is not an ancestor or descendant of class B, then it doesn't matter which appears first.  Eg. the following is wrong: try { ... } catch (Exception ex ) { . . . } catch (ArithmeticException ex ) { . . . }
  • 5. Multiple catch Control Flow  Question: Is this ok?: try { ... } catch (NumberFormatException ex ) { . . . } catch (ArithmeticException ex ) { . . . }
  • 6. The finally Block  There are situations where we need to take certain actions regardless of whether an exception is thrown or not.  We place statements that must be executed regardless of exceptions in the finally block. try { // statements, some of which might // throw an exception } catch ( SomeExceptionType ex ) { // statements to handle this // type of exception } catch ( AnotherExceptionType ex ) { // statements to handle this // type of exception } finally { // statements which will execute no matter // how the try block was exited. }