[Edit]I didn't see Sane's post when I wrote this. Grumpy's article has a lot more usefule information than my examples below [/edit]
Here is an simple example: suppose you want to divide one number by another but you are concerned that divide-by-zero error may occur
int main
{
int a = 10;
int b = 0;
int c = 0;
try
{
c = a / b;
}
catch(...)
{
cout << "Division by zero\n";
}
}
Here is another -- the
new operator throws an exception if memory allocation error occurs (such as out of memory)
int main()
{
int * array;
try
{
array = new int[10000000];
}
catch(...)
{
cout << "Oops!\n";
}
}