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.

A
catch (...)
{
}
will catch any throw without considering what kind of object was thrown and without giving access to the thrown object.

Writing

throw

Within 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;
     }

Related Topics: catch, try

Личные инструменты
Пространства имён
Варианты
Действия
Навигация
Инструменты
На других языках