M
ma740988
The hierachy for standard exception lists:
bad_alloc, bad_cast, bad_typeid, logic_error, ios_base::failure,
runtime_error and bad_exception
runtime_error and logic_error has subsets.
The question: If I threw all seven exceptions highlighted above.
std::exception is the only exception needed within the catch clause?
In other words I wouldn't need a 'catch all'? So now:
void my_test()
{
try {
// throw any or all seven above:
}
catch(std::exception& err)
{
err.what();
}
}
No need for:
void my_test()
{
try {
// throw any or all seven above:
}
catch(std::exception& err)
{
err.what();
}
catch (...)
{
// just in case.
}
}
I realize I could provide my own named exception but I'm just trying
to ensure I understand what I'm reading about std::exception:
-------------------------
Not sure where in my readings I may have missed this, nonetheless, with
deference to options 1 and 2 below, I dont think I fully understand
why std::fill does not work with option 2?
// Option 1
struct my_struct {
int my_vec[65535];
my_struct()
{ std::fill (&my_vec[0], &my_vec[65535], 0x555); }
};
//Option 2.
typedef std::vector<int> myIntVec;
struct my_struct2 {
myIntVec my_vec[65535];
my_struct2()
{ std::fill (&my_vec[0], &my_vec[65535], 0x555); }
};
I understand the obvious - i.e lets add a third option:
// Option 3
struct my_struct3 {
myIntVec my_vec;
my_struct3()
: my_vec(65535, 0x555) {}
};
Thanks in advance.
bad_alloc, bad_cast, bad_typeid, logic_error, ios_base::failure,
runtime_error and bad_exception
runtime_error and logic_error has subsets.
The question: If I threw all seven exceptions highlighted above.
std::exception is the only exception needed within the catch clause?
In other words I wouldn't need a 'catch all'? So now:
void my_test()
{
try {
// throw any or all seven above:
}
catch(std::exception& err)
{
err.what();
}
}
No need for:
void my_test()
{
try {
// throw any or all seven above:
}
catch(std::exception& err)
{
err.what();
}
catch (...)
{
// just in case.
}
}
I realize I could provide my own named exception but I'm just trying
to ensure I understand what I'm reading about std::exception:
-------------------------
Not sure where in my readings I may have missed this, nonetheless, with
deference to options 1 and 2 below, I dont think I fully understand
why std::fill does not work with option 2?
// Option 1
struct my_struct {
int my_vec[65535];
my_struct()
{ std::fill (&my_vec[0], &my_vec[65535], 0x555); }
};
//Option 2.
typedef std::vector<int> myIntVec;
struct my_struct2 {
myIntVec my_vec[65535];
my_struct2()
{ std::fill (&my_vec[0], &my_vec[65535], 0x555); }
};
I understand the obvious - i.e lets add a third option:
// Option 3
struct my_struct3 {
myIntVec my_vec;
my_struct3()
: my_vec(65535, 0x555) {}
};
Thanks in advance.