mirror of
https://github.com/epasveer/seer.git
synced 2026-08-29 16:40:42 +08:00
29 lines
442 B
C++
29 lines
442 B
C++
#include <iostream>
|
|
#include <stdexcept>
|
|
|
|
int AddPositiveIntegers (int a, int b) {
|
|
|
|
if (a < 0 || b < 0) {
|
|
throw std::invalid_argument("AddPositiveIntegers arguments must be positive");
|
|
}
|
|
|
|
return a + b;
|
|
}
|
|
|
|
int main() {
|
|
|
|
try {
|
|
|
|
std::cout << AddPositiveIntegers(-1, 2); //exception
|
|
|
|
} catch (std::invalid_argument& e) {
|
|
|
|
std::cerr << e.what() << std::endl;
|
|
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|