throw expression
De cppreference.com
[] |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
Indique une condition d'erreur et excute un gestionnaire d'erreur .
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.
Syntaxe
throw expression
|
(1) | ||||||||
throw
|
(2) | ||||||||
Explication
- Voirbloc try-catchpour plus d'informations propos de essayer et' capture (gestionnaire d'exception) blocsOriginal: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.Original:Seebloc try-catchfor 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.
1)
L'expression jet construit un objet temporaire de stockage spcifi, avec le mme type que
expression (avec CV-qualificatifs limin et le type de tableau de conversion de pointeur pour T T et T de la fonction de retour un pointeur de fonction de retour T, au besoin) , et l'initialise partir expression de la mme manire un les arguments des fonctions ou valeurs de retour sont initialises partir des paramtres de la fonction ou de l'argument d'une expression return (c.-copie lision et la construction dmnagement aura lieu si possible). L'objet exception persiste jusqu' ce que la clause catch dernire se termine ou jusqu' ce que le dernier std::exception_ptr qui fait rfrence cet objet est dtruit .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.
Une fois l'objet exception est construit, le flux de contrle fonctionne l'envers (la pile des appels) jusqu' ce qu'il atteigne le dbut d'un bloc
try, quel point les paramtres des blocs catch associs sont compares la expression lanc pour trouver une correspondance. Si aucune correspondance n'est trouve, le flux de contrle continue dtendre la pile jusqu' ce que le bloc try suivante, et ainsi de suite. Si une correspondance est trouve, les sauts de flux de contrle passe au bloc catch correspondant (le gestionnaire d'exception'), qui s'excute normalement .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.
Comme le flux de contrle dplace la pile des appels, les destructeurs sont appels pour tous les objets avec
dure de stockage automatique
construit depuis le corrlatif try-block a t conclu, dans l'ordre inverse de la construction. Si une exception est leve partir d'un constructeur, les destructeurs sont appels pour toutes entirement construits non statiques non-membres de variantes et classes de base. Ce processus est appel' pile dnouement .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 '
dure de stockage automatique
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.
2)
La remise expression sans un oprande ne peut tre utilis l'intrieur d'un bloc catch (il appelle std::terminate si utilise). Il abandonne l'excution du bloc catch et passe le contrle la clause catch correspondant suivant la pile des appels (mais pas un autre clause catch aprs le mme bloc try), la rutilisation de l'objet exception existante: pas de nouveaux objets sont faits .
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.
Voir std::terminate et std::unexpected pour la gestion des erreurs qui surviennent pendant le traitement des exceptions .
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.
D'utilisation
Bien throw-expression peut tre utilise pour transfrer le contrle un bloc de code arbitraire jusqu' la pile d'excution, pour des raisons arbitraires (similaire std::longjmp), son utilisation prvue est la gestion des erreurs .
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.
Erreur de manipulation
Lancer une exception est utilis pour signaler les erreurs de fonctions, o les erreurs sont gnralement limits seulement ce qui suit Erreur de rfrence: Balise fermante
</ref> manquante pour la balise <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.
# Dfaillances d'tablir des invariants
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.
# Incapacit de rgler les postconditions
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.
# Manquements aux conditions de l'appelant
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.
En particulier, cela implique que les dfaillances des constructeurs et la plupart des oprateurs doivent tre dclars en lanant des exceptions .
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.
Exception de scurit
Aprs que la condition d'erreur est signal par une fonction, des garanties supplmentaires peuvent tre prvues en ce qui concerne l'tat du programme. Les quatre niveaux de garantie exception sont gnralement reconnus B. Erreur de rfrence: Balise fermante
</ref> manquante pour la balise <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 (ou nofail) garantie exception - la fonction ne lve jamais les exceptions .
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.
# Garantie exception Forte - Si la fonction lve une exception, l'tat du programme est restaure l'tat juste avant l'appel de fonction .
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.
# Garantie exception Basic - Si la fonction lve une exception, le programme est dans un tat valide. Il peut exiger de nettoyage, mais tous les invariants sont intacts .
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.
# Aucune garantie exception - Si la fonction lve une exception, le programme peut ne pas tre dans un tat valide: fuites de ressources, la corruption de la mmoire, ou d'autres invariants qui dtruisent des erreurs ont pu se produire .
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.
Objets d'exception
Alors que les objets de toute nature complte et des pointeurs cv vide peut tre jet comme des objets d'exception, toutes les fonctions de la bibliothque standard jeter anonymes objets temporaires en valeur, et les types de ces objets sont issus (directement ou indirectement) de std::exception. Exceptions dfinies par l'utilisateur suivent gnralement ce processus. Erreur de rfrence: Balise fermante
</ref> manquante pour la balise <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.
Pour viter la copie inutile de l'objet exception et l'objet trancher, la meilleure pratique pour les clauses de prises est d'attraper par rfrence. Erreur de rfrence: Balise fermante
</ref> manquante pour la balise <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.
Mots-cls
Exemple
| This section is incomplete |
Rfrences
- 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.
Voir aussi
- bloc try-catchOriginal: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. - noexcept spcificateurOriginal: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. - spcifications d'exceptionOriginal: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.