Standard                     exceptions      •       What is the “exception” ?      •       What can we do with it?      •...
“Exception” aha now I got it                    what is it!!!!!                 IT’s the   “‫“واسطه‬            No!!! I’ll...
ExceptionsExceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferr...
• #include <iostream>• using namespace std;                                   Example :• int main () {• try     // Our sta...
• he code under exception handling is enclosed in a try block. In this  example this code simply throws an exception:••   ...
Example• If we use an ellipsis (...) as the parameter of  catch, that handler will catch any exception no  matter what the...
•   In this case the last handler would catch any exception thrown with any parameter that    is neither an int nor a char...
• Now I think you have an idea about the                 “ Exception “ Yes I think I started to make an idea      about th...
The commands of library exception   All exceptions thrown by components of the C++ Standard library throw exceptions   der...
For example, if we use the operator new and the memory cannot be allocated, an        exception of type bad_alloc is throw...
• Remarkwhen you use the exceptions from the library  <exception> you must :4.But “&” after the command :->6.All exceptio...
A real example :By mody ma’ane
Exception specifications   When declaring a function we can limit the exception type it might directly or    indirectly th...
Some error codes (numbers) we                                   G                                                         ...
Don by : ->• Mohammad al hsan .->•                 <-Mohammad Abu Zina .• Loay kreshan .->• Under the supervision of docto...
Upcoming SlideShare
Loading in …5
×

Standard exceptions

483 views

Published on

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

Standard exceptions

  1. 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. 2. “Exception” aha now I got it what is it!!!!! IT’s the “‫“واسطه‬ No!!! I’ll teal you whats exception is.By mody ma’ane
  3. 3. ExceptionsExceptions 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 insidethe try block. Exception handlers are declared with the keywordcatch, which must be placed immediately after the try block lets see an exampl :->By mody ma’ane
  4. 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. 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. 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. 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. 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. 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 softwareHow 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. 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. 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. 12. A real example :By mody ma’ane
  13. 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 typechar and returns an element of type float. The only exception that this functionmight 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 allowedBy mody ma’ane
  14. 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. 15. Don by : ->• Mohammad al hsan .->• <-Mohammad Abu Zina .• Loay kreshan .->• Under the supervision of doctor ->Weal Al- qasasBasically From:By mody ma’ane

×