try catch multiple exceptions

1
2
3
4
5
6
7
8
9
try
{
   int a = b + c;
   int d = e + f;
// and so on....
}
catch(int a, int b)//wrong
{
}


what is the better way to catch multiple exceptions?..i have like 40+

thanks in advance
Last edited on
1
2
3
4
5
6
7
8
9
10
#include <exception>
[...]
try
{
	// A bunch of stuff
}
catch(std::exception& e)  //The base class for most exceptions
{
	// Handle exception
}


Like this you mean? Although I guess it depends on what kind of exceptions are being thrown in the first place.
Only one exception can be thrown at a time.
1
2
3
4
5
6
7
8
9
10
11
12
try
{
	// and so on....
}
catch(int a)
{
	// If an int is thrown this catch block will handle it.
}
catch(bool b) // if you want to catch other types you just add another catch block like this.
{
	// If a bool is thrown this catch block will handle it.
}
Topic archived. No new replies allowed.