SlideShare a Scribd company logo
UNIT - III
C++ PROGRAMMING ADVANCED
FEATURES
EXCEPTION HANDLING
• An exception is a problem that arises during the
execution of a program. A C++ exception is a
response to an exceptional circumstance that arises
while a program is running, such as an attempt to
divide by zero.
• Exceptions provide a way to transfer control from
one part of a program to another.
• C++ exception handling is built upon three
keywords: try, catch and throw.
• try: A try block identifies a block of code for which
particular exceptions will be activated. It's followed
by one or more catch blocks.
• catch: A program catches an exception with an
exception handler at the place in a program where
you want to handle the problem. The catch keyword
indicates the catching of an exception.
• throw: A program throws an exception when a
problem shows up. This is done using
a throw keyword.
Syntax for try/catch block:
try
{
// protected code
}
catch( ExceptionName e1 )
{
// catch block
}
catch( ExceptionName e2 )
{
// catch block
}
catch( ExceptionName eN )
{
// catch block
}
Throwing Exceptions
• Exceptions can be thrown anywhere within a
code block using throw statements.
Syntax:
throw(exception);
throw exception;
throw;
Exception handling using try, throw
and catch expression
Try block
Involves a function which
contains an exception
Catch block
Catches and handles the
exception
Throw block
Function that causes
an exceprion
Example Program:
int main()
{
int x = -1;
cout << "Before try n";
try {
cout << "Inside try n";
if (x < 0)
{
throw x;
cout << "After throw (Never executed) n";
}
}
catch (int x ) {
cout << "Exception Caught n";
}
cout << "After catch (Will be executed) n";
return 0;
}
Output:
Before try
Inside try
Exception Caught
After catch (Will be executed)
Divide by Zero
int main()
{
int dividend, divisor, quotient;
try
{
cout<<“enter the dividend:”;
cin>>dividend;
cout<<“enter the divisor:”;
cin>>divisor;
if(divisor==0)
throws divisor;
quotient=dividend/divisor;
Cout<<“Quotient=“<<quotent;
}
catch(int)
{
cout<<“Division by Zero”;
}
return 0;
}
STANDARD LIBRARIES
• Standard function library:
– It consists of general-purpose and stand alone
functions that are not part of any class.
– These functions perform essential services such as
• Input
• Output
• Implementation of other operations
It is inherited from C.
• Object oriented class library:
– It consists of a collection of classes and associated
functions.
– It support common activities, including
• I/O
• Strings
• Numeric processing
The standard C++ library includes
• The language support library
• The diagnostics library
• The general utility library
• The standard string template
• Localization classes and template
• The standard template library
• The standard numerics library
• The standard I/O library
• C++ header for the standard C library
The language support library
• It defines types and functions that will be used
implicitly by c++ programs.
• <new> - low level memory management utilities
• <memory> - higher level memory management
utilities
• <delete> - to deallocate the memory
• <exception> - exception handling utilities
• <typeinfo> - runtime information utilities
The diagnostics library
• Used to detect and report error conditions
• <stdexcept> - standard exception objects
• <system_error> - a platform_dependent error
code
• <cerrno> - macro containing the last error
number
The general utility library
• Especially by the STL which includes
Containers, Iterators and Algorithms libraries.
• <utility> - including utility components
• <cstdlib> - general purpose utilities:random
numbers, program control, sorting
and searching
• <ctime> - C style time/date utilities
The standard string template
• <ctype> - functions to determine the type
contained in C data
• <cstring> - character string handling functions
• <string> - handles string class functionalities
Localization classes and template
• Localization library permits a C++ program to
address the cultural differences of its various
users.
• <locale> - Localization utilities
• <clocale> - C Localization utilities
• <codecvt> - unicode convertion facilities
The standard template library
• Container
– <vector>
– <list>
– <set>
– <multiset>
– <map>
• Iterators :
– <iterator>
Algorithm:
• <algorithm>
The standard I/O libraries
• <iostream>
• <fstream>
• <sstream>
• <iomanip>
• <cstdio>

More Related Content

What's hot

0.my book draft chap 1
0.my book draft chap 10.my book draft chap 1
0.my book draft chap 1
manhduc1811
 
Python Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M21 - Exception HandlingPython Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M21 - Exception Handling
P3 InfoTech Solutions Pvt. Ltd.
 
[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3
Seok-joon Yun
 
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
Rodolfo Carvalho
 
2.Format Strings
2.Format Strings2.Format Strings
2.Format Strings
phanleson
 
Hacking 101
Hacking 101Hacking 101
Tu1
Tu1Tu1
Simware framework hello world: A webinar
Simware framework hello world: A webinarSimware framework hello world: A webinar
Simware framework hello world: A webinar
José Ramón Martínez Salio
 
Lab 3
Lab 3Lab 3

What's hot (9)

0.my book draft chap 1
0.my book draft chap 10.my book draft chap 1
0.my book draft chap 1
 
Python Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M21 - Exception HandlingPython Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M21 - Exception Handling
 
[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3
 
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
 
2.Format Strings
2.Format Strings2.Format Strings
2.Format Strings
 
Hacking 101
Hacking 101Hacking 101
Hacking 101
 
Tu1
Tu1Tu1
Tu1
 
Simware framework hello world: A webinar
Simware framework hello world: A webinarSimware framework hello world: A webinar
Simware framework hello world: A webinar
 
Lab 3
Lab 3Lab 3
Lab 3
 

Similar to Unit iii pds

Lecture 09 Exception Handling(1 ) in c++.pptx
Lecture 09 Exception Handling(1 ) in c++.pptxLecture 09 Exception Handling(1 ) in c++.pptx
Lecture 09 Exception Handling(1 ) in c++.pptx
ZenLooper
 
Unit iii
Unit iiiUnit iii
Unit iii
snehaarao19
 
UNIT III.ppt
UNIT III.pptUNIT III.ppt
UNIT III.ppt
Ajit Mali
 
UNIT III (2).ppt
UNIT III (2).pptUNIT III (2).ppt
UNIT III (2).ppt
VGaneshKarthikeyan
 
Exceptionn
ExceptionnExceptionn
Exception
ExceptionException
Exception
Harry Potter
 
Exception
ExceptionException
Exception
Tony Nguyen
 
Exception
ExceptionException
Exception
Luis Goldster
 
Exception
ExceptionException
Exception
Young Alista
 
Exception
ExceptionException
Exception
Hoang Nguyen
 
Exception
ExceptionException
Exception
James Wong
 
Exception
ExceptionException
Exception
Fraboni Ec
 
Exception
ExceptionException
Exception
Tony Nguyen
 
Exception
ExceptionException
Exception
Fraboni Ec
 
Exception handling
Exception handlingException handling
Exception handling
Waqas Abbasi
 
43c
43c43c
Lecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxLecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptx
VishuSaini22
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Handling
HandlingHandling
Handling
Amit Vats
 
6-Exception Handling and Templates.pptx
6-Exception Handling and Templates.pptx6-Exception Handling and Templates.pptx
6-Exception Handling and Templates.pptx
SatyamMishra237306
 

Similar to Unit iii pds (20)

Lecture 09 Exception Handling(1 ) in c++.pptx
Lecture 09 Exception Handling(1 ) in c++.pptxLecture 09 Exception Handling(1 ) in c++.pptx
Lecture 09 Exception Handling(1 ) in c++.pptx
 
Unit iii
Unit iiiUnit iii
Unit iii
 
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
 
Exceptionn
ExceptionnExceptionn
Exceptionn
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception handling
Exception handlingException handling
Exception handling
 
43c
43c43c
43c
 
Lecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxLecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptx
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Handling
HandlingHandling
Handling
 
6-Exception Handling and Templates.pptx
6-Exception Handling and Templates.pptx6-Exception Handling and Templates.pptx
6-Exception Handling and Templates.pptx
 

Recently uploaded

Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
Shiny Christobel
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
MadhavJungKarki
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
Atif Razi
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
Addu25809
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
Indrajeet sahu
 
Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...
cannyengineerings
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
sydezfe
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
PriyankaKilaniya
 
AI-Based Home Security System : Home security
AI-Based Home Security System : Home securityAI-Based Home Security System : Home security
AI-Based Home Security System : Home security
AIRCC Publishing Corporation
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
b0754201
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
upoux
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
PreethaV16
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
Kamal Acharya
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
um7474492
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
PreethaV16
 

Recently uploaded (20)

Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
 
Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
 
AI-Based Home Security System : Home security
AI-Based Home Security System : Home securityAI-Based Home Security System : Home security
AI-Based Home Security System : Home security
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
 

Unit iii pds

  • 1. UNIT - III C++ PROGRAMMING ADVANCED FEATURES
  • 2. EXCEPTION HANDLING • An exception is a problem that arises during the execution of a program. A C++ exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero. • Exceptions provide a way to transfer control from one part of a program to another. • C++ exception handling is built upon three keywords: try, catch and throw.
  • 3. • try: A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks. • catch: A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception. • throw: A program throws an exception when a problem shows up. This is done using a throw keyword.
  • 4. Syntax for try/catch block: try { // protected code } catch( ExceptionName e1 ) { // catch block } catch( ExceptionName e2 ) { // catch block } catch( ExceptionName eN ) { // catch block }
  • 5. Throwing Exceptions • Exceptions can be thrown anywhere within a code block using throw statements. Syntax: throw(exception); throw exception; throw;
  • 6. Exception handling using try, throw and catch expression Try block Involves a function which contains an exception Catch block Catches and handles the exception Throw block Function that causes an exceprion
  • 7. Example Program: int main() { int x = -1; cout << "Before try n"; try { cout << "Inside try n"; if (x < 0) { throw x; cout << "After throw (Never executed) n"; } } catch (int x ) { cout << "Exception Caught n"; } cout << "After catch (Will be executed) n"; return 0; } Output: Before try Inside try Exception Caught After catch (Will be executed)
  • 8. Divide by Zero int main() { int dividend, divisor, quotient; try { cout<<“enter the dividend:”; cin>>dividend; cout<<“enter the divisor:”; cin>>divisor; if(divisor==0) throws divisor; quotient=dividend/divisor; Cout<<“Quotient=“<<quotent; } catch(int) { cout<<“Division by Zero”; } return 0; }
  • 9. STANDARD LIBRARIES • Standard function library: – It consists of general-purpose and stand alone functions that are not part of any class. – These functions perform essential services such as • Input • Output • Implementation of other operations It is inherited from C.
  • 10. • Object oriented class library: – It consists of a collection of classes and associated functions. – It support common activities, including • I/O • Strings • Numeric processing
  • 11. The standard C++ library includes • The language support library • The diagnostics library • The general utility library • The standard string template • Localization classes and template • The standard template library • The standard numerics library • The standard I/O library • C++ header for the standard C library
  • 12. The language support library • It defines types and functions that will be used implicitly by c++ programs. • <new> - low level memory management utilities • <memory> - higher level memory management utilities • <delete> - to deallocate the memory • <exception> - exception handling utilities • <typeinfo> - runtime information utilities
  • 13. The diagnostics library • Used to detect and report error conditions • <stdexcept> - standard exception objects • <system_error> - a platform_dependent error code • <cerrno> - macro containing the last error number
  • 14. The general utility library • Especially by the STL which includes Containers, Iterators and Algorithms libraries. • <utility> - including utility components • <cstdlib> - general purpose utilities:random numbers, program control, sorting and searching • <ctime> - C style time/date utilities
  • 15. The standard string template • <ctype> - functions to determine the type contained in C data • <cstring> - character string handling functions • <string> - handles string class functionalities
  • 16. Localization classes and template • Localization library permits a C++ program to address the cultural differences of its various users. • <locale> - Localization utilities • <clocale> - C Localization utilities • <codecvt> - unicode convertion facilities
  • 17. The standard template library • Container – <vector> – <list> – <set> – <multiset> – <map>
  • 18. • Iterators : – <iterator> Algorithm: • <algorithm>
  • 19. The standard I/O libraries • <iostream> • <fstream> • <sstream> • <iomanip> • <cstdio>