Q:

exception catching for int divided by 0

Recently i was trying a simple exception program in C++ which goes like this:-
#include <iostream>
#include <exception>
#include <stdexcept>
using namespace std;
int main()
{
    int x=5, y=0;
    try
    {
       int z=x/y;
       cout<<"z="<<z;
    }
    catch (exception& e)
    {
       cout<<"exception caught: "<<e.what();
    }
    return 0;
}

Why is no exception thrown here ? What is wrong in the code ?
Also I would like to know why the & is required to catch exception ?

A:

Any integer when divided by zero is not an exception in standard C++.
The section 5.6 of C++ states:

If the second operand of / or % is zero, the behavior is undefined.

You may also find it interesting to read this:

Stroustrup says, in "The Design and Evolution of C++" (Addison Wesley,
  1994), "low-level events, such as arithmetic overflows and divide by
  zero, are assumed to be handled by a dedicated lower-level mechanism
  rather than by exceptions. This enables C++ to match the behaviour of
  other languages when it comes to arithmetic. It also avoids the
  problems that occur on heavily pipelined architectures where events
  such as divide by zero are asynchronous."`

A:

For the second question:
We catch exceptions by reference (&) because polymorphic types can only act "polymorphically" through a pointer or a reference. Exceptions are polymorphic types, because we can have multiple classes deriving from std::exception that we want to catch generically.
Since by convention we throw exceptions by value, only references can work at the catch site.

