International Research Journal of Engineering and Technology (IRJET) Volume: 04 Issue: 02 | Feb -2017
www.irjet.net
e-ISSN: 2395 -0056 p-ISSN: 2395-0072
Exceptions and Exception Handling in C++ ANURAG SINGH Dr.APJ Abdul Kalam Technical University Uttar Pradesh Department of Computer Science and engineering, IEC College of Engineering & Technology, Uttar Pradesh, India. ---------------------------------------------------------------------***--------------------------------------------------------------------1.1 Program for Demo of Exception: to the occurrence, during computation, of exceptions or #include<iostream.h> exceptional conditions requiring special processing .An void main() exception is a problem that arises during the execution of { the program. A C++ exceptions a type of response for an Int a, b, x; exceptional situation that arises while a program is running, in such types of situation as an attempt to divide by cout<<”Enter two numbers\n”; zero. The errors occurred in program may be logical errors cin>>a>>b; or syntactic errors. The logical errors remains in the x=a/b; program due to an unsatisfactory understanding of the cout<<a<<”/”<<b<<”=”<<x; program. The goal of exception handling is to create a } routine that detect and sends an exceptional condition in
Abstract - Exception handling is the process of responding
order to execute suitable actions.
Output 1
Key Words: Exceptions, try, catch, throw, re-throwing.
Enter two numbers 20 5 20/5 = 4
Introduction: Exceptions are errors that occur at run time. They are caused by a wide variety of exceptional circumstance, such as running out of memory, not being able to open a file, trying to initialize an object to an impossible value, or using an out - of - bounds index to a vector. An exception is an error or an expected event. The exception handler is a set of codes that executes when an exception occurs. Exception handling is one of the most recently added features in C++. Exception handling in C++ provides a better method by which the caller of a function can be informed that some error condition has occurred. The following keywords are used for error handling in C++.
Output 2 Enter two numbers 13 0 Not produce any output but will terminate abnormally and produce an exception divide- error.
2. Process:
Try Catch Throw
Sometimes the application makes a mistake, causing an error to be detected in a member function. This member function then informs the application that an error has occurred. When exceptions are used, this is called throwing an exception. In this application we install a separate section of code to handle the error. This code is called an exception handler or catch block, It catches the exceptions thrown by the number function. Any code in application that uses object of the class is enclosed in a try block. Error generate in the block will be caught in the catch block.
An exception also known as run time errors because these are occurs at runtime. For example there may be an abnormal condition or unexpected behavior when we try to divide a number by zero or an array is accessed outside of it’s bounds, or when required memory is not available, etc.
© 2017, IRJET
|
Impact Factor value: 5.181
|
ISO 9001:2008 Certified Journal
|
Page 293