Espacios de nombres
Variantes
Acciones

throw expression

De cppreference.com
< cpp‎ | language

 
 
Lenguaje C++
Los temas generales
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Control de flujo
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Sentencias condicionales ejecución
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Instrucciones de iteración
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Ir declaraciones
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funciones
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declaración de la función
lambda declaración de la función
función de plantilla
especificador inline
especificaciones de excepción (obsoleto)
noexcept especificador (C++11)
Excepciones
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
tirar expresión
Los espacios de nombres
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
Los especificadores
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cv especificadores
almacenamiento duración especificadores
constexpr especificador (C++11)
auto especificador (C++11)
alignas especificador (C++11)
Inicialización
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los literales
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expresiones
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
representaciones alternativas
Utilidades
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
alias de tipo de declaración (C++11)
atributos (C++11)
Lanza
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversiones implícitas
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-cast estilo y funcional
De asignación de memoria
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Clases
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Clase propiedades específicas de la función
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funciones especiales miembro
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Plantillas
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
clase de plantilla
función de plantilla
plantilla de especialización
paquetes de parámetros (C++11)
Varios
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaje en línea
 
Señala que una condición errónea y ejecuta un controlador de errores .
Original:
Signals an erroneous condition and executes an error handler.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Contenido

[editar] Sintaxis

throw expression (1)
throw (2)

[editar] Explicación

para más información sobre intentan y captura (manejador de excepciones) bloques
1)
La expresión banda construye un objeto temporal en almacenamiento no especificado, con el mismo tipo que expression (con CV-calificadores eliminado y convertido en el tipo de matriz de T a puntero a T y de T a una función que devuelve puntero a función que regresa T, según sea necesario) y lo inicializa desde expression de la misma manera a los argumentos de función o valores de retorno se inicia a partir de los parámetros de la función o el argumento de una expresión return (es decir elisión copia y construcción de movimiento tendrá lugar si es posible). El objeto de excepción se mantiene hasta la última cláusula catch completa o hasta que el último std::exception_ptr que hace referencia este objeto se destruye .
Original:
The throw expression constructs a temporary object in unspecified storage, with the same type as expression (with cv-qualifiers removed and the type converted from array of T to pointer to T and from function returning T to pointer to function returning T, as necessary), and initializes it from expression in the same manner a function arguments or return values are initialized from the function parameters or the argument of a return expression (i.e. copy elision and move construction take place if possible). The exception object persists until the last catch clause completes or until the last std::exception_ptr that references this object is destroyed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Una vez que el objeto de excepción se construye, el flujo de control funciona hacia atrás (hasta la pila de llamadas) hasta que alcanza el principio de un bloque try, momento en el que los parámetros de los bloques catch asociados se comparan con la expression lanzado para encontrar una coincidencia. Si no se encuentra una coincidencia, el flujo de control continúa para desenrollar la pila hasta que el bloque try siguiente, y así sucesivamente. Si se encuentra una coincidencia, los saltos de flujo de control al bloque catch juego (el manejador de excepciones'), que ejecuta normalmente .
Original:
Once the exception object is constructed, the control flow works backwards (up the call stack) until it reaches the start of a try block, at which point the parameters of the associated catch blocks are compared with the thrown expression to find a match. If no match is found, the control flow continues to unwind the stack until the next try block, and so on. If a match is found, the control flow jumps to the matching catch block (the exception handler), which executes normally.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
construido desde el correspondiente bloque try-ha entrado, en orden inverso al de la construcción. Si se produce una excepción de un constructor, los destructores son llamados para todas totalmente construidas no estáticos no variante miembros y clases base. Este proceso se llama' desenredo de pila .
Original:
As the control flow moves up the call stack, destructors are invoked for all objects with '
duración de almacenamiento automático
Original:
automatic storage duration
The text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
</div>
constructed since the corresponding try-block was entered, in reverse order of construction. If an exception is thrown from a constructor, destructors are called for all fully-constructed non-static non-variant members and base classes. This process is called stack unwinding.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
El saque de expresión sin un operando sólo se puede utilizar dentro de un bloque catch (lo llama std::terminate si se utiliza otro tipo). Se abandona la ejecución del bloque catch y pasa el control a la cláusula catch coincidente anterior de la pila de llamadas (pero no a otra cláusula catch después de que el mismo bloque try), reutilizando el objeto de excepción existente: no hay objetos nuevos se hacen .
Original:
The throw-expression without an operand may only be used inside a catch block (it calls std::terminate if used otherwise). It abandons the execution of the catch block and passes control to the next matching catch clause up the call stack (but not to another catch clause after the same try block), reusing the existing exception object: no new objects are made.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Ver std::terminate y std::unexpected para el manejo de errores que surgen durante el manejo de excepciones .
Original:
See std::terminate and std::unexpected for the handling of errors that arise during exception handling.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Usage

Mientras banda expresión se puede usar para transferir el control a un bloque de código arbitrario de la pila de ejecución, por razones arbitrarias (similar a std::longjmp), su uso previsto una gestión de errores .
Original:
While throw-expression can be used to transfer control to an arbitrary block of code up the execution stack, for arbitrary reasons (similar to std::longjmp), its intended usage is error handling.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Gestión de errores

Lanzar una excepción se utiliza para señalar los errores de las funciones, en los "errores" son por lo general limitados a sólo el siguiente Error en la cita: Etiqueta de apertura <ref> sin su correspondiente cierre </ref>[1]:
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
# Fallas establecer invariantes
Original:
# Failures to establish invariants
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
# De incumplimiento de las condiciones posteriores
Original:
# Failures to meet the postconditions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
# De incumplimiento de las condiciones previas de la persona que llama
Original:
# Failures to meet the preconditions of the caller
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
En particular, esto implica que el fracaso de la mayoría de los constructores y los operadores deben ser reportados por lanzar excepciones .
Original:
In particular, this implies that the failures of constructors and most operators should be reported by throwing exceptions.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Excepción de seguridad

Después de que la condición de error es reportado por una función, garantías adicionales se pueden proporcionar con respecto al estado del programa. Los siguientes cuatro niveles de garantía excepción son generalmente reconocidos B. Error en la cita: Etiqueta de apertura <ref> sin su correspondiente cierre </ref>[2][3], which are strict supersets of each other:
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
# Nothrow (o nofail) Garantía de excepción - nunca la función arroja excepciones .
Original:
# Nothrow (or nofail) exception guarantee -- the function never throws exceptions.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
# Garantía excepción Fuerte - Si la función produce una excepción, el estado del programa se revierte al estado justo antes de la llamada a la función .
Original:
# Strong exception guarantee -- If the function throws an exception, the state of the program is rolled back to the state just before the function call.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
# Garantía excepción básico - Si la función produce una excepción, el programa está en un estado válido. Se puede requerir limpieza, pero todos los invariantes están intactos .
Original:
# Basic exception guarantee -- If the function throws an exception, the program is in a valid state. It may require cleanup, but all invariants are intact.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
# Ninguna garantía excepción - Si la función produce una excepción, el programa no puede estar en un estado válido: las pérdidas de recursos, la corrupción de la memoria, u otros errores que destruyen invariante puede haber ocurrido .
Original:
# No exception guarantee -- If the function throws an exception, the program may not be in a valid state: resource leaks, memory corruption, or other invariant-destroying errors may have occurred.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Los objetos de excepción

Si bien objetos de ningún tipo completo y punteros cv para anular puede ser lanzado como objetos de excepción, todas las funciones de la biblioteca estándar anónimos tirar objetos temporales por valor y los tipos de los objetos se derivan (directa o indirectamente) de std::exception. Excepciones definidas por el usuario por lo general siguen este patrón. Error en la cita: Etiqueta de apertura <ref> sin su correspondiente cierre </ref>[4]
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Para evitar la copia innecesaria del objeto de excepción y el objeto rebanado, la mejor práctica para cláusulas catch es coger como referencia. Error en la cita: Etiqueta de apertura <ref> sin su correspondiente cierre </ref>[5][6]
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Palabras clave

throw

[editar] Ejemplo

[editar] Referencias

  1. H.Sutter, A. Alexandrescu (2004), "C++ Coding Standards", Item 70
  2. H. Sutter (2000) "Exceptional C++"
  3. D. Abrahams (2001) "Exception Safety in Generic Components"
  4. M. Cline, C++FAQ Lite 17.11
  5. M. Cline, C++FAQ Lite 17.12
  6. H.Sutter, A. Alexandrescu (2004) "C++ Coding Standards" Item 73
Original:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Ver también