+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
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.
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)
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.
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
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