#include <iostream>
usingnamespace std;
bool isPrime(int n) {
if( n <= 1 )
throw n; //throw exception (type int)
for( int i = n - 1; i > 1; i-- )
if( n % i == 0 )
returnfalse;
returntrue;
}
void printIsPrime(int n) {
cout << "Is " << n << " prime: " << (isPrime(n) ? "yes" : "no") << endl;
}
int main() {
int a = 5,
b = 10,
c = -1,
d = 2;
try {
printIsPrime(a);
printIsPrime(b);
printIsPrime(c); //try to jump to the catch block of the appropriate type
printIsPrime(d);
} catch(int num) {
//int exceptions thrown in the above try block will be handled here
cerr << "isPrime failed on " << num << endl;
}
return 0;
}