1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
/* +------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| https://www.mrpt.org/ |
| |
| Copyright (c) 2005-2023, Individual contributors, see AUTHORS file |
| See: https://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See: https://www.mrpt.org/License |
+------------------------------------------------------------------------+ */
/** \example core_exceptions_example/test.cpp */
//! [example-nested-exceptions]
#include <mrpt/core/exceptions.h>
#include <iostream>
void test_except_3rd_lvl()
{
MRPT_START
THROW_EXCEPTION("Aw!");
MRPT_END
}
void test_except_2nd_lvl()
{
MRPT_START
test_except_3rd_lvl();
MRPT_END
}
void test_except_toplevel()
{
MRPT_START
test_except_2nd_lvl();
MRPT_END
}
void test_except_2nd_lvl_bis()
{
MRPT_START
std::vector<int> x;
x.resize(2);
x.at(10); // throws
MRPT_END
}
void test_except_toplevel_bis() { test_except_2nd_lvl_bis(); }
int main()
{
try
{
test_except_toplevel();
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what();
}
try
{
test_except_toplevel_bis();
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what();
}
return 0;
}
//! [example-nested-exceptions]
|