SlideShare a Scribd company logo
1 of 8
Constness, Exceptions and other
             stuff
Const pointers
•   const int i
•   const int* i
•   int const* i
•   int* const i;
Const references
• const int& i
• int const& i
Const methods
•   void foo() const
•   Only methods can be const
•   Static methods can’t be const
•   mutable members
Explicit constructors
• Implicit type casting
• It can be bad in some cases
• Explicit constructors
Exceptions
• It should be preferred over return codes
• Exceptions should be caught as high as
  possible
• Wildcard catch
• Do not ignore exceptions
Catching by reference
• Prefer to catch exceptions by reference
• Reference should be const unless you want to
  edit exception
• You can catch derived exceptions by reference
  to base exception
Standard exceptions
• exception
• runtime_error
• range_error, overflow_error, underflow_error,
  system_error
• logic_error
• domain_error, invalid_argument, length_error,
  out_of_range

More Related Content

Viewers also liked

Viewers also liked (8)

Export management ppt
Export management pptExport management ppt
Export management ppt
 
Import,export procedure
Import,export procedureImport,export procedure
Import,export procedure
 
Export procedure
Export procedureExport procedure
Export procedure
 
EXPORT PROCEDURE & DOCUMENTATION
EXPORT PROCEDURE & DOCUMENTATIONEXPORT PROCEDURE & DOCUMENTATION
EXPORT PROCEDURE & DOCUMENTATION
 
Export Procedures and Documents
Export Procedures and DocumentsExport Procedures and Documents
Export Procedures and Documents
 
Import & export presentation
Import & export presentationImport & export presentation
Import & export presentation
 
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATION
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATIONA PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATION
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATION
 
EXPORT IMPORT
EXPORT IMPORTEXPORT IMPORT
EXPORT IMPORT
 

More from Amazon Web Services

More from Amazon Web Services (12)

cpp-2013 #19 Concurrency
cpp-2013 #19 Concurrencycpp-2013 #19 Concurrency
cpp-2013 #19 Concurrency
 
cpp-2013 #15 Databases
cpp-2013 #15 Databasescpp-2013 #15 Databases
cpp-2013 #15 Databases
 
cpp-2013 #14 Основи Qt
cpp-2013 #14 Основи Qtcpp-2013 #14 Основи Qt
cpp-2013 #14 Основи Qt
 
cpp-2013 #13 C++11
cpp-2013 #13 C++11cpp-2013 #13 C++11
cpp-2013 #13 C++11
 
cpp-2013 #9 STL Algorithms Part 1
cpp-2013 #9 STL Algorithms Part 1cpp-2013 #9 STL Algorithms Part 1
cpp-2013 #9 STL Algorithms Part 1
 
cpp-2013 #8 STL Containers Part 2
cpp-2013 #8 STL Containers Part 2cpp-2013 #8 STL Containers Part 2
cpp-2013 #8 STL Containers Part 2
 
cpp-2013 #7 Templates and STL Containers
cpp-2013 #7 Templates and STL Containerscpp-2013 #7 Templates and STL Containers
cpp-2013 #7 Templates and STL Containers
 
cpp-2013 #6 OOP Part 2
cpp-2013 #6 OOP Part 2cpp-2013 #6 OOP Part 2
cpp-2013 #6 OOP Part 2
 
cpp-2013 #5 File and network input/output
cpp-2013 #5 File and network input/outputcpp-2013 #5 File and network input/output
cpp-2013 #5 File and network input/output
 
cpp-2013 #3 OOP Basics
cpp-2013 #3 OOP Basicscpp-2013 #3 OOP Basics
cpp-2013 #3 OOP Basics
 
cpp-2013 #2 Organizing your code
cpp-2013 #2 Organizing your codecpp-2013 #2 Organizing your code
cpp-2013 #2 Organizing your code
 
cpp-2013 #1 C++ basics
cpp-2013 #1 C++ basicscpp-2013 #1 C++ basics
cpp-2013 #1 C++ basics
 

cpp-2013 #11 Constness and Exceptions