Namespace
Varianti

throw expression

Da cppreference.com.
< cpp‎ | language

 
 
Linguaggio C + +
Temi generali
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.
Controllo del flusso
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.
Dichiarazioni esecuzione condizionale
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.
Iterazione dichiarazioni
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.
Vai dichiarazioni
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.
Funzioni
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dichiarazione di funzione
lambda funzione dichiarazione
funzione di modello
specificatore inline
eccezioni specifiche (deprecato)
noexcept specificatore (C++11)
Eccezioni
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
tiro espressione
Spazi dei nomi
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
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)
Specifiers
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 specificatori
Durata di stoccaggio specificatori
constexpr specificatore (C++11)
specificatore auto (C++11)
alignas specificatore (C++11)
Inizializzazione
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Letterali
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Espressioni
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rappresentazioni alternative
Utilities
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
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
Tipo alias dichiarazione (C++11)
attributi (C++11)
Lancia
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversioni implicite
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Fusione C-stile e funzionale
Occupazione della 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.
Classi
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Specifiche per una classe di funzioni proprietà
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.
esplicito (C++11)
statico
Funzioni membro speciali
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.
Modelli
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
classe template
funzione di modello
modello di specializzazione
parametri confezioni (C++11)
Varie
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaggio in linea
 
Segnali di una condizione erronea ed esegue un gestore di errori.
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.

Indice

[modifica] Sintassi

throw expression (1)
throw (2)

[modifica] Spiegazione

per ulteriori informazioni su provare e cattura (gestore di eccezioni) blocchi
1)
L'espressione throw costruisce un oggetto temporaneo stoccaggio non specificato, con lo stesso tipo expression (con CV-qualificatori rimosso e il tipo di conversione da array di T a puntatore a T e dalla funzione che restituisce T a puntatore a funzione che restituisce T, se necessario) , e si inizializza dalla expression nello stesso modo di un argomenti della funzione o valori restituiti vengono inizializzati dai parametri di funzione o l'argomento di un'espressione return (cioè elisione copia e spostamento di costruzione luogo se possibile). L'oggetto eccezione persiste fino a che la clausola di cattura completa o fino a quando l'ultimo std::exception_ptr che fa riferimento a questo oggetto viene distrutto.
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 volta che l'oggetto eccezione è costruito, il flusso di controllo funziona all'indietro (fino allo stack) fino a raggiungere l'inizio di un blocco try, a questo punto vengono confrontati i parametri dei blocchi catch associati al expression gettato per trovare una corrispondenza. Se non viene trovata, il flusso di controllo continua a svolgere la pila finché il blocco try successivo, e così via. Se viene trovata una corrispondenza, il controllo passa al blocco del flusso catch corrispondente (il gestore di eccezioni'), che viene eseguito 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.
costruito in quanto il corrispondente try-blocco è stato inserito, in ordine inverso di costruzione. Se viene generata un'eccezione da un costruttore, distruttori sono chiamati per tutti completamente costruite non statici non varianti membri e le classi base. Questo processo è chiamato' la rimozione dello stack.
Original:
As the control flow moves up the call stack, destructors are invoked for all objects with '
memorizzazione automatica durata
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)
Il tiro-espressione senza un operando può essere utilizzato solo all'interno di un blocco catch (lo chiama std::terminate se utilizzati in altro modo). Si abbandona l'esecuzione del blocco catch e passa il controllo alla successiva clausola catch corrispondente lo stack di chiamate (ma non in un altro punto fermo dopo il blocco try stesso), riutilizzando l'oggetto esistente eccezione: non nuovi oggetti sono fatti.
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.
Vedi std::terminate std::unexpected e per la gestione degli errori che si verificano durante la gestione delle eccezioni.
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.

[modifica] Utilizzo

Mentre laterale espressione può essere usato per trasferire il controllo a un blocco di codice arbitrario la stack di esecuzione, per ragioni arbitrarie (simile a std::longjmp), il suo uso previsto è la gestione degli errori.
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.

[modifica] La gestione degli errori

Lanciare una eccezione viene utilizzata per segnalare errori di funzioni, in cui "errori" sono in genere limitati al solo le seguenti Errore nella funzione Cite: </ref> di chiusura mancante per il marcatore <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.
# Errori di stabilire invarianti
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.
# Errori per soddisfare le post
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.
# Casi di inosservanza delle condizioni del chiamante
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.
In particolare, ciò implica che i fallimenti dei costruttori e la maggior parte degli operatori devono essere segnalati da buttare eccezioni.
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.

[modifica] Eccezione di sicurezza

Dopo l'errore è segnalato da una funzione, garanzie supplementari possono essere fornite per quanto riguarda lo stato del programma. Le seguenti quattro livelli di garanzia eccezione sono generalmente riconosciuti B. Errore nella funzione Cite: </ref> di chiusura mancante per il marcatore <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) garanzia eccezione - mai la funzione genera eccezioni.
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.
# Garanzia eccezione forte - Se la funzione genera un'eccezione, lo stato del programma viene ripristinato allo stato poco prima della chiamata di funzione.
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.
# Garanzia eccezione di base - Se la funzione genera un'eccezione, il programma è in uno stato valido. Si può richiedere la pulizia, ma tutte le invarianti sono intatte.
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.
# Nessuna garanzia eccezione - Se la funzione genera un'eccezione, il programma potrebbe non essere in uno stato valido: perdite di risorse, la corruzione di memoria, o altri invarianti che distruggono errori potrebbe essersi verificato.
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.

[modifica] Eccezione oggetti

Mentre gli oggetti di qualsiasi tipo completo e puntatori cv revocatorie possono essere gettati come oggetti di eccezione, tutte le funzioni della libreria standard lanciare anonimi oggetti temporanei per valore, e il tipo di tali oggetti sono derivati ​​(direttamente o indirettamente) da std::exception. Eccezioni definite dall'utente seguono solitamente questo schema. Errore nella funzione Cite: </ref> di chiusura mancante per il marcatore <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.
Per evitare la copia non necessaria l'oggetto eccezione e oggetto affettatura, la migliore pratica per clausole catch è quello di prendere per riferimento. Errore nella funzione Cite: </ref> di chiusura mancante per il marcatore <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.

[modifica] Parole chiave

throw

[modifica] Esempio

[modifica] Riferimenti

  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.

[modifica] Vedi anche