SlideShare a Scribd company logo
1 of 42
Exception handling
 Exception refers to unexpected condition in the
program.
 The unusual condition could be faults which may
cause the failure of a system.
 The error handling mechanism is called as exception
handling.
 Exceptions are classified into synchronous and asynchronous
exceptions.
 The exceptions which occur during the program execution, due to
some fault in the input-data or technique that is not suitable to
handle the current class of data, within the program, arc known as
synchronous exceptions.
 For instance, errors such as out-of-range, overflow, underflow, and
so on belong to the class of synchronous exceptions.
 The exceptions caused by events or faults unrelated (external) to
the program and beyond the control of program are called
asynchronous exceptions. For instance, errors such as keyboard
interrupts, hardware malfunctions, disk failure, and so on belong to
the class of asynchronous exceptions.
 The proposed exception handling mechanism in C++ is designed to
handle only synchronous exceptions caused within a program.
Exception Handling Model
 When a program encounters an abnormal situation for which it is
not designed, the user may transfer control to some other part of
the program that is designed to deal with the problem. This is
done by throwing an exception.
 The exception-handling mechanism uses three blocks: try, throw,
and catch.
throw Construct
catch Construct
try Construct
 The mechanism suggests that error handling code must perform
the following tasks.
 Detect the problem causing exception (Hit the exception)
 Inform that an error has occurred (Throw the exception)
 Receive the error information (Catch the exception)
 Take corrective actions (Handle the exceptions)
Handler Throwing the Same Exception Again
 List of Exceptions
Exceptions in Constructors and Destructors
 Example
Handling Uncaught Exceptions
 The uncaught exception handling mechanism relies on two library
functions, terminate() and unexpected ( ) ,for coping with
exceptions unhandled explicitly. C++ supports the following
special functions to handle uncaught exceptions in a systematic
manner:
 terminate()
 set_terminate ( )
 unexpected()
 set_unexpected()
terminate()
The function terminate () is invoked when an exception is
raised and the handler is not found. The default action for
terminate is to invoke abort (). Such a default action causes
immediate termination of the program execution.
 Example
set_terminate()
The set_terminate function allows the user to install a
function that defines the program’s actions to be taken to
terminate the program when a handler for the exception
cannot be found. The actions are defined in t_func, which
is declared to be a function of type terminate_function. A
terminate_function type defined in except .h/exception, is
a function that takes no arguments, and returns nothing.
Example
unexpected()
 The unexpected function is called when a function throws an
exception not listed in its exception specification. The program
calls unexpected () which calls any user-defined function
registered by set_unexpected. If no function is registered with
set_unexpected, the unexpected() function then invokes the
terminate () function.
 Example
set_unexpected()
The function set_unexpected() lets the user to install a
function that defines the program’s actions to be taken
when a function throws an exception not listed in its
exception specification. The actions are defined in
unexpected_func() library function. By default, an
unexpected exception causes unexpected() to be called,
which in turn calls unexpected_func.
 Example
Namespace
 Example
A namespace (sometimes also called a name scope) is an abstract container or
environment created to hold a logical grouping of unique identifiers or symbols
(i.e., names). An identifier defined in a namespace is associated only with that
namespace. The same identifier can be independently defined in multiple
namespaces.
Introduction to the STL
 The STL contains several kinds of entities. The three most
important are
 containers,
algorithms, and
iterators.
Container
 A container is a way that stored data is organized in memory.
 Arrays, Stacks , Queue etc.
 The STL containers are implemented by template classes, so they
can be easily customized to hold different kinds of data.
Algorithms
Algorithms in the STL are procedures that are applied to
containers to process their data in various ways. For
example, there are algorithms to sort. copy, search, and
merge data.
Algorithms are represented by template functions. These
functions are not member functions of the container
classes. Rather they are standalone functions.
Iterators
Iterators are a generalization of the concept of pointers:
they point to elements in a container.
You can increment an iterator, as you can a pointer, so it
points in turn to each element in a container.
Iterators are a key part of the STL because they connect
algorithms with containers.
Containers…………
Containers in the STL fall into two main categories:
sequence and associative.
The sequence containers are vector. list, and deque.
The associative containers are set. multiset, map. and
multimap.
In addition, several specialized containers are derived from
the sequence containers.
Sequence Container
A sequence container stores a set of elements in what you
can visualize as a line
Each element is related to the other elements by its
position along the line.
Each element (except at the ends) is preceded by one
specific element and followed by another.
An ordinary C++ array is an example of a sequence
container.
Associative Containers
An associative container is not sequential: instead it uses
keys to access data.
The keys, typically numbers or stings, are used
automatically by the container to arrange the stored
elements in a specific order.
It’s like an ordinary English dictionary, in which you access
data by looking up words arranged in alphabetical order.
and the container converts this key to the element’s
location in memory. If you know the key. you can access the
associated value swiftly.
There are two kinds of associative containers in the STL:
sets and maps.
These both store data in a structure called a tree, which
offers fast searching, insertion, and deletion. Sets and maps
are thus very versatile general data structures suitable for a
wide variety of applications.
However, it is inefficient to son them and perform other
operations that require random access.
Member functions
Container Adapters
 Vector Example
 Deque Example
 Set Example
Algorithms
Algorithm
 find()
 Count()
 Sort()
 Search()
 Merge()
Function objects
Some algorithms can take something called a function
object as an argument. A function object looks, to the user,
much like a template function. However, it's actually an
object of a template class that has a single member
function: the overloaded () operator.
Example
User-written Functions in Place of Function Objects
 Example
Member Functions swap(), emptv(), back() and pop back()
 Example
Iterators
 Iterators can be used as smart pointers and
connection between algorithm and containers.
 Smart pointers:
 float* ptr = start_address
for(int j=0; j<SIZE; j++)
cout <<*ptr++;
 Example
Reverse Iterators
Stream Iterators
 Stream iterators allow you to treat files and I/O devices (such as
cm and cout) as if they were iterators. This makes it easy to use
files and I/O devices as arguments to algorithms.
 The major purpose of the input and output iterator categories is to
support these stream iterator classes.
 Stream iterators are actually objects of classes that are templetized
for different types of input or output. There are two stream
iterators: ostream_iterator and istream_iterator.
 Example
Storing Using defined objects
 Example

More Related Content

What's hot

java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part ii
jyoti_lakhani
 
Generic Programming &amp; Collection
Generic Programming &amp; CollectionGeneric Programming &amp; Collection
Generic Programming &amp; Collection
Arya
 

What's hot (20)

Arrays Fundamentals Unit II
Arrays  Fundamentals Unit IIArrays  Fundamentals Unit II
Arrays Fundamentals Unit II
 
Exploiting JXL using Selenium
Exploiting JXL using SeleniumExploiting JXL using Selenium
Exploiting JXL using Selenium
 
Java.util
Java.utilJava.util
Java.util
 
statement interface
statement interface statement interface
statement interface
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database Models
 
java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part ii
 
8 if
8 if8 if
8 if
 
Oracle: Cursors
Oracle: CursorsOracle: Cursors
Oracle: Cursors
 
Server-Solvers-Interacter-Interfacer-Modeler-Presolver Libraries and Executab...
Server-Solvers-Interacter-Interfacer-Modeler-Presolver Libraries and Executab...Server-Solvers-Interacter-Interfacer-Modeler-Presolver Libraries and Executab...
Server-Solvers-Interacter-Interfacer-Modeler-Presolver Libraries and Executab...
 
Net framework session01
Net framework session01Net framework session01
Net framework session01
 
Sql server ___________session_18(stored procedures)
Sql server  ___________session_18(stored procedures)Sql server  ___________session_18(stored procedures)
Sql server ___________session_18(stored procedures)
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
WEKA: Data Mining Input Concepts Instances And Attributes
WEKA: Data Mining Input Concepts Instances And AttributesWEKA: Data Mining Input Concepts Instances And Attributes
WEKA: Data Mining Input Concepts Instances And Attributes
 
Java Tutorial Lab 2
Java Tutorial Lab 2Java Tutorial Lab 2
Java Tutorial Lab 2
 
Xpath
XpathXpath
Xpath
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
 
java collections
java collectionsjava collections
java collections
 
IO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingIO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxing
 
Generic Programming &amp; Collection
Generic Programming &amp; CollectionGeneric Programming &amp; Collection
Generic Programming &amp; Collection
 

Viewers also liked (6)

App Promotion Summit: leverage reviews for ASO
App Promotion Summit: leverage reviews for ASOApp Promotion Summit: leverage reviews for ASO
App Promotion Summit: leverage reviews for ASO
 
ASOBarcamp 2 - Ratings and Reviews - ASO Impact and Leverage
ASOBarcamp 2 - Ratings and Reviews - ASO Impact and LeverageASOBarcamp 2 - Ratings and Reviews - ASO Impact and Leverage
ASOBarcamp 2 - Ratings and Reviews - ASO Impact and Leverage
 
Reviews & Ratings - Thomasbcn 2016 @ Applause.io
Reviews & Ratings - Thomasbcn 2016 @ Applause.ioReviews & Ratings - Thomasbcn 2016 @ Applause.io
Reviews & Ratings - Thomasbcn 2016 @ Applause.io
 
TargetSummit Berlin Meetup | 8Fit, Thomas Petit
TargetSummit Berlin Meetup | 8Fit, Thomas PetitTargetSummit Berlin Meetup | 8Fit, Thomas Petit
TargetSummit Berlin Meetup | 8Fit, Thomas Petit
 
ASO: A/B Testing your store listing
ASO: A/B Testing your store listingASO: A/B Testing your store listing
ASO: A/B Testing your store listing
 
Apple Search Ads - App Promotion Summit Berlin 2016
Apple Search Ads - App Promotion Summit Berlin 2016Apple Search Ads - App Promotion Summit Berlin 2016
Apple Search Ads - App Promotion Summit Berlin 2016
 

Similar to Unit v

Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
Jake Bond
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
karymadelaneyrenne19
 

Similar to Unit v (20)

(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii
 
Data structures
Data structuresData structures
Data structures
 
Unit iii
Unit iiiUnit iii
Unit iii
 
Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
UNIT III.ppt
UNIT III.pptUNIT III.ppt
UNIT III.ppt
 
UNIT III (2).ppt
UNIT III (2).pptUNIT III (2).ppt
UNIT III (2).ppt
 
C++
C++C++
C++
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdf
 
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptxKripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
Buffer overflow attacks
Buffer overflow attacksBuffer overflow attacks
Buffer overflow attacks
 
DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
CSE 443 (1).pptx
CSE 443 (1).pptxCSE 443 (1).pptx
CSE 443 (1).pptx
 
Stl dich
Stl dichStl dich
Stl dich
 
Ch08
Ch08Ch08
Ch08
 
Ch08
Ch08Ch08
Ch08
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
 
Bt0065
Bt0065Bt0065
Bt0065
 

More from donny101 (9)

Unit iv
Unit ivUnit iv
Unit iv
 
Unit iii
Unit iiiUnit iii
Unit iii
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
Unit 1
Unit  1Unit  1
Unit 1
 
Unit vos - File systems
Unit vos - File systemsUnit vos - File systems
Unit vos - File systems
 
Unit ivos - file systems
Unit ivos - file systemsUnit ivos - file systems
Unit ivos - file systems
 
Unit iios process scheduling and synchronization
Unit iios process scheduling and synchronizationUnit iios process scheduling and synchronization
Unit iios process scheduling and synchronization
 
Unit iiios Storage Management
Unit iiios Storage ManagementUnit iiios Storage Management
Unit iiios Storage Management
 
Unit 1os processes and threads
Unit 1os processes and threadsUnit 1os processes and threads
Unit 1os processes and threads
 

Recently uploaded

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
rknatarajan
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 

Unit v

  • 1.
  • 2. Exception handling  Exception refers to unexpected condition in the program.  The unusual condition could be faults which may cause the failure of a system.  The error handling mechanism is called as exception handling.
  • 3.  Exceptions are classified into synchronous and asynchronous exceptions.  The exceptions which occur during the program execution, due to some fault in the input-data or technique that is not suitable to handle the current class of data, within the program, arc known as synchronous exceptions.  For instance, errors such as out-of-range, overflow, underflow, and so on belong to the class of synchronous exceptions.  The exceptions caused by events or faults unrelated (external) to the program and beyond the control of program are called asynchronous exceptions. For instance, errors such as keyboard interrupts, hardware malfunctions, disk failure, and so on belong to the class of asynchronous exceptions.  The proposed exception handling mechanism in C++ is designed to handle only synchronous exceptions caused within a program.
  • 4. Exception Handling Model  When a program encounters an abnormal situation for which it is not designed, the user may transfer control to some other part of the program that is designed to deal with the problem. This is done by throwing an exception.  The exception-handling mechanism uses three blocks: try, throw, and catch.
  • 5.
  • 9.  The mechanism suggests that error handling code must perform the following tasks.  Detect the problem causing exception (Hit the exception)  Inform that an error has occurred (Throw the exception)  Receive the error information (Catch the exception)  Take corrective actions (Handle the exceptions)
  • 10. Handler Throwing the Same Exception Again  List of Exceptions
  • 11. Exceptions in Constructors and Destructors  Example
  • 12. Handling Uncaught Exceptions  The uncaught exception handling mechanism relies on two library functions, terminate() and unexpected ( ) ,for coping with exceptions unhandled explicitly. C++ supports the following special functions to handle uncaught exceptions in a systematic manner:  terminate()  set_terminate ( )  unexpected()  set_unexpected()
  • 13. terminate() The function terminate () is invoked when an exception is raised and the handler is not found. The default action for terminate is to invoke abort (). Such a default action causes immediate termination of the program execution.  Example
  • 14. set_terminate() The set_terminate function allows the user to install a function that defines the program’s actions to be taken to terminate the program when a handler for the exception cannot be found. The actions are defined in t_func, which is declared to be a function of type terminate_function. A terminate_function type defined in except .h/exception, is a function that takes no arguments, and returns nothing. Example
  • 15. unexpected()  The unexpected function is called when a function throws an exception not listed in its exception specification. The program calls unexpected () which calls any user-defined function registered by set_unexpected. If no function is registered with set_unexpected, the unexpected() function then invokes the terminate () function.  Example
  • 16. set_unexpected() The function set_unexpected() lets the user to install a function that defines the program’s actions to be taken when a function throws an exception not listed in its exception specification. The actions are defined in unexpected_func() library function. By default, an unexpected exception causes unexpected() to be called, which in turn calls unexpected_func.  Example
  • 17. Namespace  Example A namespace (sometimes also called a name scope) is an abstract container or environment created to hold a logical grouping of unique identifiers or symbols (i.e., names). An identifier defined in a namespace is associated only with that namespace. The same identifier can be independently defined in multiple namespaces.
  • 18. Introduction to the STL  The STL contains several kinds of entities. The three most important are  containers, algorithms, and iterators.
  • 19. Container  A container is a way that stored data is organized in memory.  Arrays, Stacks , Queue etc.  The STL containers are implemented by template classes, so they can be easily customized to hold different kinds of data.
  • 20. Algorithms Algorithms in the STL are procedures that are applied to containers to process their data in various ways. For example, there are algorithms to sort. copy, search, and merge data. Algorithms are represented by template functions. These functions are not member functions of the container classes. Rather they are standalone functions.
  • 21. Iterators Iterators are a generalization of the concept of pointers: they point to elements in a container. You can increment an iterator, as you can a pointer, so it points in turn to each element in a container. Iterators are a key part of the STL because they connect algorithms with containers.
  • 22.
  • 23. Containers………… Containers in the STL fall into two main categories: sequence and associative. The sequence containers are vector. list, and deque. The associative containers are set. multiset, map. and multimap. In addition, several specialized containers are derived from the sequence containers.
  • 24. Sequence Container A sequence container stores a set of elements in what you can visualize as a line Each element is related to the other elements by its position along the line. Each element (except at the ends) is preceded by one specific element and followed by another. An ordinary C++ array is an example of a sequence container.
  • 25.
  • 26.
  • 27. Associative Containers An associative container is not sequential: instead it uses keys to access data. The keys, typically numbers or stings, are used automatically by the container to arrange the stored elements in a specific order. It’s like an ordinary English dictionary, in which you access data by looking up words arranged in alphabetical order. and the container converts this key to the element’s location in memory. If you know the key. you can access the associated value swiftly.
  • 28. There are two kinds of associative containers in the STL: sets and maps. These both store data in a structure called a tree, which offers fast searching, insertion, and deletion. Sets and maps are thus very versatile general data structures suitable for a wide variety of applications. However, it is inefficient to son them and perform other operations that require random access.
  • 29.
  • 30.
  • 33.  Vector Example  Deque Example  Set Example
  • 35. Algorithm  find()  Count()  Sort()  Search()  Merge()
  • 36. Function objects Some algorithms can take something called a function object as an argument. A function object looks, to the user, much like a template function. However, it's actually an object of a template class that has a single member function: the overloaded () operator. Example
  • 37. User-written Functions in Place of Function Objects  Example Member Functions swap(), emptv(), back() and pop back()  Example
  • 38. Iterators  Iterators can be used as smart pointers and connection between algorithm and containers.  Smart pointers:  float* ptr = start_address for(int j=0; j<SIZE; j++) cout <<*ptr++;  Example
  • 39.
  • 41. Stream Iterators  Stream iterators allow you to treat files and I/O devices (such as cm and cout) as if they were iterators. This makes it easy to use files and I/O devices as arguments to algorithms.  The major purpose of the input and output iterator categories is to support these stream iterator classes.  Stream iterators are actually objects of classes that are templetized for different types of input or output. There are two stream iterators: ostream_iterator and istream_iterator.  Example
  • 42. Storing Using defined objects  Example