SlideShare une entreprise Scribd logo
1  sur  15
Standard
                     exceptions
      •       What is the “exception” ?
      •       What can we do with it?
      •       What is the commands of library exception?
      •       How to use the library exception ?
      •       what is Exception specifications?


By mohamad al~hsan
“Exception” aha now I got it
                    what is it!!!!!

                 IT’s the   “‫“واسطه‬
            No!!! I’ll teal you what's
                 exception is.

By mody ma’ane
Exceptions
Exceptions provide a way to react to exceptional circumstances
 (like runtime errors) in our program by transferring control to
                special functions called handlers.

   To catch exceptions we must place a portion of code under
  exception inspection. This is done by enclosing that portion of
  code in a try block. When an exceptional circumstance arises
   within that block, an exception is thrown that transfers the
 control to the exception handler. If no exception is thrown, the
      code continues normally and all handlers are ignored.

 An exception is thrown by using the throw keyword from inside
the try block. Exception handlers are declared with the keyword
catch, which must be placed immediately after the try block lets
                        see an exampl :->
By mody ma’ane
• #include <iostream>
• using namespace std;                                   Example :
• int main () {
• try     // Our star the “TRY” we are saying to the compiler try this code if its good
•    //let it work but if it makes a problems pass some thing else (it can be any thing you wont)
•      {
•          throw 20;    //it means throw the thing you wont ?? Cane we throw rocks ??
•    //no we can throw only expression as one param in this case it’s int (20) .
•      }//ok if we throw the expression who is going to catch it
•    //the catch fun will do it Of course
•      catch (int e)
•      {//but can we throw a char and catch an int?? No it must be from the same
     kind        .
•   cout << "An exception occurred. Exception Nr. " << e <<
  endl;
• }//now I started to understand .
•     return 0;
• }
By mody ma’ane
• he code under exception handling is enclosed in a try block. In this
  example this code simply throws an exception:
•


•    A throw expression accepts one parameter (in this case the integer
     value 20), which is passed as an argument to the exception handler.

•     The exception handler is declared with the catch keyword. As you can
     see, it follows immediately the closing brace of the try block. The catch
     format is similar to a regular function that always has at least one
     parameter. The type of this parameter is very important, since the type
     of the argument passed by the throw expression is checked against it,
     and only in the case they match, the exception is caught.

•     We can chain multiple handlers (catch expressions), each one with a
     different parameter type. Only the handler that matches its type with
     the argument specified in the throw statement is executed.




By mody ma’ane
Example
• If we use an ellipsis (...) as the parameter of
  catch, that handler will catch any exception no
  matter what the type of the throw exception is.
  This can be used as a default handler that catches
  all exceptions not caught by other handlers if it is
  specified at last :->




By mody ma’ane
•   In this case the last handler would catch any exception thrown with any parameter that
    is neither an int nor a char.

•    After an exception has been handled the program execution resumes after the try-
    catch block, not after the throw statement!.

•    It is also possible to nest try-catch blocks within more external try blocks. In these
    cases, we have the possibility that an internal catch block forwards the exception to its
    external level. This is done with the expression throw; with no arguments. For example:




                                                                                       By mody ma’ane
• Now I think you have an idea about the


                 “ Exception “
 Yes I think I started to make an idea
      about the whole thing.
          ok lets go on>>>
By mody ma’ane
The commands of library exception
   All exceptions thrown by components of the C++ Standard library throw exceptions
   derived from this std::exception class. These are:




   NumericalError     do specific handling for a numerical error.
   LapackError        handle any other LapackError .
     and a lots of commands but these are the most important>>
Woooow now I’m confused there is a lots of commands!! LAPACK (Linear Algebra
                                                         PACKage) is a software
How do they work ??                                      library for numerical
                                                         linear algebra. It provides
        Don’t worry I’ll teal you how to work with them. routines forlinear
                                                         systems of
                                                                       solving

                                                                           equations and linear

            Ok lets see                                                    least squares,
                                                                           eigenvalue problems,
By mody ma’ane                                                             and singular value
For example, if we use the operator new and the memory cannot be allocated, an
        exception of type bad_alloc is thrown : as:->




    That’s where the errors in the windows come from ?

  Yes, my friend when “example:” you try to Reserve a place in the memory that the
  system can’t reserve you will see the fowling error “Error allocating memory. ” or ”
  The system cant allocate memory.”


By mody ma’ane
• Remark

when you use the exceptions from the library
  <exception> you must :
4.But “&” after the command :->

6.All exceptions thrown by components of the C++
  Standard library throw exceptions derived from
  this std::exception class.


By mody ma’ane
A real example :




By mody ma’ane
Exception specifications
   When declaring a function we can limit the exception type it might directly or
    indirectly throw by appending a throw suffix to the function declaration:
                        float myfunction (char param) throw (int);

 This declares a function called myfunction which takes one argument of type
char and returns an element of type float. The only exception that this function
might throw is an exception of type int. If it throws an exception with a different
   type, either directly or indirectly, it cannot be caught by a regular int-type
                                       handler.

  If this throw specifies is left empty with no type, this means the function is not
      allowed to throw exceptions. Functions with no throw specifier (regular
              functions) are allowed to throw exceptions with any type:
                 int myfunction (int param) throw(); // no exceptions allowed
              int myfunction (int param);      // all exceptions allowed

By mody ma’ane
Some error codes (numbers) we                                   G
                                                                           o
                      can use                                              o
      • 530 : No enough memory         •‘C' Packets error codes:           d
• 1021 : Error while validation of
                        parameter      • 407:Error while writing given     T
     • 510 : No enough space for       file                                h
          moving home directory        • 405:Error while opening given     i
   • 507 : Unable to update/read       file                                n
                         group file    • 406:Error while reading given
                                                                           g
        • 902 : Unable to get the      file
                                       • 411 :Unable to read socket        s
                  Container Root
                                       • 412 :Unable to write socket
• 911 : Error while parsing config     • C06 :(Unable to return required   T
                               file.                                       o
                                       value)
    • 1012 : Host name is invalid      • C08 :(Parse or Syntax error in
  • 1315 : Unable to get memory        the passed in CLIPS                 K
                       information     expressions)                        n
       • 'C++' Utility error codes:    • S00 :(Internal generic system
                                                                           o
 • 101:connection to agent failed      error)
                                                                           w
 • 100:unable to save the ssh key      • C01 :(Unable to create a
                                       system object)
By mody ma’ane
                                       • C04 :(This file unable to open)
Don by : ->
• Mohammad al hsan .->

•                 <-Mohammad Abu Zina .

• Loay kreshan .->

• Under the supervision of doctor
  ->Weal Al- qasas
Basically From:


By mody ma’ane

Contenu connexe

Tendances

Control statements
Control statementsControl statements
Control statementsraksharao
 
Exception Handling1
Exception Handling1Exception Handling1
Exception Handling1guest739536
 
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b....NET Conf UY
 
Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]ppd1961
 
Java New Programming Features
Java New Programming FeaturesJava New Programming Features
Java New Programming Featurestarun308
 
Exception Handling in the C++ Constructor
Exception Handling in the C++ ConstructorException Handling in the C++ Constructor
Exception Handling in the C++ ConstructorSomenath Mukhopadhyay
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayAlexis Gallagher
 
The operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerAndrey Karpov
 
Exceptions handling in java
Exceptions handling in javaExceptions handling in java
Exceptions handling in javajunnubabu
 

Tendances (12)

Control statements
Control statementsControl statements
Control statements
 
Exception Handling1
Exception Handling1Exception Handling1
Exception Handling1
 
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
 
Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
C++ boot camp part 1/2
C++ boot camp part 1/2C++ boot camp part 1/2
C++ boot camp part 1/2
 
Java New Programming Features
Java New Programming FeaturesJava New Programming Features
Java New Programming Features
 
Exception Handling in the C++ Constructor
Exception Handling in the C++ ConstructorException Handling in the C++ Constructor
Exception Handling in the C++ Constructor
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That Way
 
The operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzer
 
Exceptions handling in java
Exceptions handling in javaExceptions handling in java
Exceptions handling in java
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 

Similaire à Standard exceptions

Exceptions overview
Exceptions overviewExceptions overview
Exceptions overviewBharath K
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingAboMohammad10
 
A36519192_21789_4_2018_Exception Handling.ppt
A36519192_21789_4_2018_Exception Handling.pptA36519192_21789_4_2018_Exception Handling.ppt
A36519192_21789_4_2018_Exception Handling.pptpromila09
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javaAdil Mehmoood
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allHayomeTakele
 
Exceptionhandling
ExceptionhandlingExceptionhandling
ExceptionhandlingNuha Noor
 
Exception handling
Exception handlingException handling
Exception handlingpooja kumari
 
exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2thenmozhip8
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C LanguageMohamed Elsayed
 

Similaire à Standard exceptions (20)

Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
 
A36519192_21789_4_2018_Exception Handling.ppt
A36519192_21789_4_2018_Exception Handling.pptA36519192_21789_4_2018_Exception Handling.ppt
A36519192_21789_4_2018_Exception Handling.ppt
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Exception handling
Exception handlingException handling
Exception handling
 
exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C Language
 
Exception hierarchy
Exception hierarchyException hierarchy
Exception hierarchy
 
Java chapter 6
Java chapter 6Java chapter 6
Java chapter 6
 
06 exceptions
06 exceptions06 exceptions
06 exceptions
 

Dernier

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Dernier (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

Standard exceptions

  • 1. Standard exceptions • What is the “exception” ? • What can we do with it? • What is the commands of library exception? • How to use the library exception ? • what is Exception specifications? By mohamad al~hsan
  • 2. “Exception” aha now I got it what is it!!!!! IT’s the “‫“واسطه‬ No!!! I’ll teal you what's exception is. By mody ma’ane
  • 3. Exceptions Exceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to special functions called handlers. To catch exceptions we must place a portion of code under exception inspection. This is done by enclosing that portion of code in a try block. When an exceptional circumstance arises within that block, an exception is thrown that transfers the control to the exception handler. If no exception is thrown, the code continues normally and all handlers are ignored. An exception is thrown by using the throw keyword from inside the try block. Exception handlers are declared with the keyword catch, which must be placed immediately after the try block lets see an exampl :-> By mody ma’ane
  • 4. • #include <iostream> • using namespace std; Example : • int main () { • try // Our star the “TRY” we are saying to the compiler try this code if its good • //let it work but if it makes a problems pass some thing else (it can be any thing you wont) • { • throw 20; //it means throw the thing you wont ?? Cane we throw rocks ?? • //no we can throw only expression as one param in this case it’s int (20) . • }//ok if we throw the expression who is going to catch it • //the catch fun will do it Of course • catch (int e) • {//but can we throw a char and catch an int?? No it must be from the same kind . • cout << "An exception occurred. Exception Nr. " << e << endl; • }//now I started to understand . • return 0; • } By mody ma’ane
  • 5. • he code under exception handling is enclosed in a try block. In this example this code simply throws an exception: • • A throw expression accepts one parameter (in this case the integer value 20), which is passed as an argument to the exception handler. • The exception handler is declared with the catch keyword. As you can see, it follows immediately the closing brace of the try block. The catch format is similar to a regular function that always has at least one parameter. The type of this parameter is very important, since the type of the argument passed by the throw expression is checked against it, and only in the case they match, the exception is caught. • We can chain multiple handlers (catch expressions), each one with a different parameter type. Only the handler that matches its type with the argument specified in the throw statement is executed. By mody ma’ane
  • 6. Example • If we use an ellipsis (...) as the parameter of catch, that handler will catch any exception no matter what the type of the throw exception is. This can be used as a default handler that catches all exceptions not caught by other handlers if it is specified at last :-> By mody ma’ane
  • 7. In this case the last handler would catch any exception thrown with any parameter that is neither an int nor a char. • After an exception has been handled the program execution resumes after the try- catch block, not after the throw statement!. • It is also possible to nest try-catch blocks within more external try blocks. In these cases, we have the possibility that an internal catch block forwards the exception to its external level. This is done with the expression throw; with no arguments. For example: By mody ma’ane
  • 8. • Now I think you have an idea about the “ Exception “ Yes I think I started to make an idea about the whole thing. ok lets go on>>> By mody ma’ane
  • 9. The commands of library exception All exceptions thrown by components of the C++ Standard library throw exceptions derived from this std::exception class. These are: NumericalError do specific handling for a numerical error. LapackError handle any other LapackError . and a lots of commands but these are the most important>> Woooow now I’m confused there is a lots of commands!! LAPACK (Linear Algebra PACKage) is a software How do they work ?? library for numerical linear algebra. It provides Don’t worry I’ll teal you how to work with them. routines forlinear systems of solving equations and linear Ok lets see least squares, eigenvalue problems, By mody ma’ane and singular value
  • 10. For example, if we use the operator new and the memory cannot be allocated, an exception of type bad_alloc is thrown : as:-> That’s where the errors in the windows come from ? Yes, my friend when “example:” you try to Reserve a place in the memory that the system can’t reserve you will see the fowling error “Error allocating memory. ” or ” The system cant allocate memory.” By mody ma’ane
  • 11. • Remark when you use the exceptions from the library <exception> you must : 4.But “&” after the command :-> 6.All exceptions thrown by components of the C++ Standard library throw exceptions derived from this std::exception class. By mody ma’ane
  • 12. A real example : By mody ma’ane
  • 13. Exception specifications When declaring a function we can limit the exception type it might directly or indirectly throw by appending a throw suffix to the function declaration: float myfunction (char param) throw (int); This declares a function called myfunction which takes one argument of type char and returns an element of type float. The only exception that this function might throw is an exception of type int. If it throws an exception with a different type, either directly or indirectly, it cannot be caught by a regular int-type handler. If this throw specifies is left empty with no type, this means the function is not allowed to throw exceptions. Functions with no throw specifier (regular functions) are allowed to throw exceptions with any type: int myfunction (int param) throw(); // no exceptions allowed int myfunction (int param); // all exceptions allowed By mody ma’ane
  • 14. Some error codes (numbers) we G o can use o • 530 : No enough memory •‘C' Packets error codes: d • 1021 : Error while validation of parameter • 407:Error while writing given T • 510 : No enough space for file h moving home directory • 405:Error while opening given i • 507 : Unable to update/read file n group file • 406:Error while reading given g • 902 : Unable to get the file • 411 :Unable to read socket s Container Root • 412 :Unable to write socket • 911 : Error while parsing config • C06 :(Unable to return required T file. o value) • 1012 : Host name is invalid • C08 :(Parse or Syntax error in • 1315 : Unable to get memory the passed in CLIPS K information expressions) n • 'C++' Utility error codes: • S00 :(Internal generic system o • 101:connection to agent failed error) w • 100:unable to save the ssh key • C01 :(Unable to create a system object) By mody ma’ane • C04 :(This file unable to open)
  • 15. Don by : -> • Mohammad al hsan .-> • <-Mohammad Abu Zina . • Loay kreshan .-> • Under the supervision of doctor ->Weal Al- qasas Basically From: By mody ma’ane