Make changes to the way to catch the bad allocation exception.

No need to catch them locally. Instead, catching them in the main
function is good enough.