Skip to content

Commit

Permalink
Exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil624 committed Mar 15, 2017
1 parent 81ebfa8 commit 5e8b928
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions except string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<iostream>
using namespace std;

int main(){
int num;

cin>>num;

try{
if(num == 0){
throw("Zero");
}

else if (num <0){
throw("Negative");
}

else{
cout<<"All good number is positive";
}
}

catch(const char *err){
cout<<"There was an error nigga. Number is "<<err;
}
}
Binary file added except string.exe
Binary file not shown.
23 changes: 23 additions & 0 deletions exception handling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
using namespace std;

int main(){
int num,den;

try{
cin>>num>>den;
if(den == 0){
throw(den);
}

else{
cout<<(num/den);
}
}

catch(int x){
cout<<"Denominator cannot be zero";
}

return 0;
}
Binary file added exception handling.exe
Binary file not shown.
Binary file modified hr.exe
Binary file not shown.

0 comments on commit 5e8b928

Please sign in to comment.