crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )

> Задачка N6
LuckLess
  опции профиля:
сообщение 11.4.2008, 11:55
Сообщение #1


Студент
*

Группа: Новичок
Сообщений: 31
Регистрация: 10.10.2007
Пользователь №: 8

Спасибо сказали: 0 раз(а)




Репутация:   0  


хых
Компилим мозгом
int main()
   {
   try
      {
      throw 5;
      }
   catch (int i)
      {
      try
         {
         ++i;
         throw;
         }
      catch (int i)
         {
         std::cout << i;
         }
      }
   }


что вылезет?
Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение
 
Начать новую тему
Ответов
archimed7592
  опции профиля:
сообщение 11.4.2008, 22:08
Сообщение #2


Участник
**

Группа: Участник
Сообщений: 127
Регистрация: 27.12.2007
Из: Moscow
Пользователь №: 56

Спасибо сказали: 0 раз(а)




Репутация:   0  


Цитата
А вот если в первом catch ловить по ссылке - будет таки 6.

Действительно :).
http://www.kuzbass.ru:8086/docs/isocpp/exc...ml#except.throw
Цитата
-3- A throw-expression initializes a temporary object, the type of which is determined by removing any top-level cv-qualifiers from the static type of the operand of throw and adjusting the type from ``array of T'' or ``function returning T'' to ``pointer to T'' or ``pointer to function returning T'', respectively. [Note: the temporary object created for a throw-expression that is a string literal is never of type char* or wchar_t*; that is, the special conversions for string literals from the types ``array of const char'' and ``array of const wchar_t'' to the types ``pointer to char'' and ``pointer to wchar_t'', respectively (conv.array), are never applied to a throw-expression. ] The temporary is used to initialize the variable named in the matching handler (except.handle). The type of the throw-expression shall not be an incomplete type, or a pointer or reference to an incomplete type, other than void*, const void*, volatile void*, or const volatile void*. Except for these restrictions and the restrictions on type matching mentioned in except.handle, the operand of throw is treated exactly as a function argument in a call (expr.call) or the operand of a return statement.

-4- The memory for the temporary copy of the exception being thrown is allocated in an unspecified way, except as noted in basic.stc.dynamic.allocation. The temporary persists as long as there is a handler being executed for that exception. In particular, if a handler exits by executing a throw; statement, that passes control to another handler for the same exception, so the temporary remains. When the last handler being executed for the exception exits by any means other than throw; the temporary object is destroyed and the implementation may deallocate the memory for the temporary object; any such deallocation is done in an unspecified way. The destruction occurs immediately after the destruction of the object declared in the exception-declaration in the handler.

http://www.kuzbass.ru:8086/docs/isocpp/exc...l#except.handle
Цитата
-19- When the handler declares a non-constant object, any changes to that object will not affect the temporary object that was initialized by execution of the throw-expression. When the handler declares a reference to a non-constant object, any changes to the referenced object are changes to the temporary object initialized when the throw-expression was executed and will have effect should that object be rethrown.
Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение

Сообщений в этой теме


Быстрый ответОтветить в данную темуНачать новую тему
Теги
Нет тегов для показа


1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0




RSS Текстовая версия Сейчас: 22.12.2024, 12:55