Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- // 1 , 2 , 3, 4 , 5 , 6, 7, 8 ,9 ,10
- // 100 112
- class Test
- {
- public:
- Test() { std::cout << "Test ctor\n"; }
- ~Test() { std::cout << "Test dtor\n"; }
- };
- int linearSearch(const int* begin, const int* const end, int key)
- {
- Test test;
- auto start{ begin };
- while (begin != end)
- {
- if (*begin == key) { return begin - start; }
- ++begin;
- }
- //std::cout << "Key don't found!\n";
- throw (float)-42;
- return -1;
- }
- int crash(int par)
- {
- std::cout << "Crash starts\n";
- if (par < 0)
- {
- throw true;
- }
- std::cout << "Crash ends\n";
- return 42;
- }
- int main()
- {
- const int arrSize{ 10 };
- int arr[arrSize]{ 1,2,3,4,5,6,7,8,9,10 };
- int exc{ 42 };
- std::cout << "Program starts\n";
- try
- {
- try
- {
- std::cout << "Pre exception\n";
- //std::cout << "Answer is: .... " << crash(-1) << '\n';
- int key{ 101 };
- std::cout << "Key ->" << key << " was found at " << linearSearch(arr+2, arr + arrSize, key) << '\n';
- std::cout << "Post exception\n";
- }
- catch (int exception)
- {
- if (exception == -42)
- {
- std::cout << "OOpps! We do not found super important data in array!\n";
- }
- else
- {
- std::cout << "Bad things, int code: " << exception << '\n';
- }
- }
- catch (char exception)
- {
- std::cout << "Bad things, char code: " << exception << '\n';
- }
- //catch (...)
- //{
- // std::cout << "Bad things, very bad!\n";
- //}
- }
- catch (float ex)
- {
- std::cout << "External try block float exception: " << ex << '\n';
- }
- std::cout << "After exception processing\n";
- std::cout << "Program ends\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement