Throw
Материал из cppreference.com
Синтаксис:
try { statement list; } catch( typeA arg ) { statement list; } catch( typeB arg ){ statement list; } ... catch( typeN arg ) { statement list; }
Выражение throw - это часть механизма С++ по обработке исключений. Это выражение, вместе с try и catch, даёт программистам элегантный механизм для исправления ошибок.
You will generally use a try block to execute potentially error-prone code. Somewhere in this code, a throw statement can be executed, which will cause execution to jump out of the try block and into one of the catch blocks.
Acatch (...) { }
Writing
throwWithin a catch block will re throw what ever was caught.
Example:
try { cout << "Before throwing exception" << endl; throw 42; cout << "Shouldn't ever see this!" << endl; } catch( int error ) { cerr << "Error: caught exception " << error << endl; }