Skip to content

Instantly share code, notes, and snippets.

@njlr
Created May 16, 2017 13:38
Show Gist options
  • Save njlr/0c6cafe38cf6e9f5c55377fc62b47b20 to your computer and use it in GitHub Desktop.
Save njlr/0c6cafe38cf6e9f5c55377fc62b47b20 to your computer and use it in GitHub Desktop.
#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