-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0037119
commit 1c33324
Showing
6 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
Object Oriented Programming/Step8_ExceptionHandling/execption.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/*There are many ways to achieve the exception handling. | ||
By simple try, throw any dataType , catch it | ||
By using multiple catches the throwed dataType matched catch block will exe. | ||
By using catch(...){} it can exe. default it can exe any throw which is firstly throwed | ||
BY throwing object use refernce of object in catch block then call the static attached error function | ||
By Inherited the Exception class to your error class and and pass the constructor msg to :exceptio(msg){} then override the virtual const char*what() const {} func by adding your won comments and then return the exception::what(); of the base class. | ||
By using system ddefaut inherited classes like bad_alloc , out_ofRange like | ||
*/ |
22 changes: 22 additions & 0 deletions
22
Object Oriented Programming/Step8_ExceptionHandling/outsideFunctionHandle.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int x, y; | ||
cout << "Enter the two numbers :\n"; | ||
cin >> x >> y; | ||
try | ||
{ | ||
if (y != 0) | ||
cout << "Divsion = " << x / y << "\n"; | ||
else | ||
throw y; | ||
} | ||
catch (int i) | ||
{ | ||
cout << "Caught y = " << i << " could not be be divisible\n"; | ||
} | ||
return 0; | ||
} |
20 changes: 20 additions & 0 deletions
20
Object Oriented Programming/Step8_ExceptionHandling/tryCatch.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() | ||
{ | ||
cout << "Code start here\n"; | ||
try | ||
{ | ||
cout << "First line executed:\n"; | ||
throw 90; | ||
cout << "This line cannot be executed due to incedently throwing an error\n"; | ||
} | ||
catch (double i) | ||
{ | ||
cout << "The execption of line " << i << " can be executed\n"; | ||
} | ||
cout << "Code ends here\n"; | ||
return 0; | ||
} |
28 changes: 28 additions & 0 deletions
28
Object Oriented Programming/Step8_ExceptionHandling/tryCatchFunctions.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
float divide(float x, float y) | ||
{ | ||
if (y != 0) | ||
cout << "Divsion = " << x / y << "\n"; | ||
else | ||
throw y; | ||
} | ||
|
||
int main() | ||
{ | ||
int x, y; | ||
cout << "Enter the two numbers :\n"; | ||
cin >> x >> y; | ||
try | ||
{ | ||
divide(x, y); | ||
} | ||
catch (float i) | ||
{ | ||
cout << "Caught y = " << i << " could not be be divisible\n"; | ||
} | ||
|
||
return 0; | ||
} |