Created
May 16, 2017 13:38
-
-
Save njlr/0c6cafe38cf6e9f5c55377fc62b47b20 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <iostream> | |
#include <string> | |
int divide(int x, int y) { | |
if (y == 0) { | |
throw std::string("Divide by zero"); | |
} | |
return x / y; | |
} | |
int main() { | |
try { | |
std::cout << "4/2 " << divide(4, 2) << std::endl; | |
std::cout << "3/0 " << divide(3, 0) << std::endl; | |
} catch(std::string e) { | |
std::cout << e << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment