 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
int
main() {
|
|
int i;
|
|
cout <<"Enter an integer:
";
|
|
cin >>i;
|
|
|
try {
|
|
if (i != 42) //detect error condition
|
|
throw i; //throw an exception
|
|
cout <<"no throw was
executed" <<endl;
|
|
}
|
|
|
catch(int x) { //catch integer
exceptions
|
|
cout <<"exception handler
called; arg = " <<x <<endl;
|
i = 42; //set it to correct value
|
|
}
|
|
|
cout <<"normal program exit;
i = " <<i <<endl;
|
|
return(0);
|
|
}
|
|