throw expression
Da cppreference.com.
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
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.
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) blocchiOriginal:Seeblocco try-catch</div> for more information about try and catch (exception handler) blocksOriginal:try-catch blockThe 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.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
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.
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.
You can help to correct and verify the translation. Click here for instructions.
Poiché il flusso di controllo si sposta lo stack di chiamate, distruttori sono invocati per tutti gli oggetti con '<div class="t-tr-text">memorizzazione automatica durata
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:
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.
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
Original:
As the control flow moves up the call stack, destructors are invoked for all objects with '
memorizzazione automatica durata</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.
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.
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Parole chiave
[modifica] Esempio
This section is incomplete |
[modifica] Riferimenti
- ↑ H.Sutter, A. Alexandrescu (2004), "C++ Coding Standards", Item 70
- ↑ H. Sutter (2000) "Exceptional C++"
- ↑ D. Abrahams (2001) "Exception Safety in Generic Components"
- ↑ M. Cline, C++FAQ Lite 17.11
- ↑ M. Cline, C++FAQ Lite 17.12
- ↑ 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.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Vedi anche
- <div class="t-tr-text"> blocco try-catch</div>Original:try-catch blockThe 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 class="t-tr-text"> noexcept specificatore</div>Original:noexcept specifierThe 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 class="t-tr-text"> eccezioni specifiche</div>Original:exception specificationsThe 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.