..
In terms of programming, except the term identifies a set of very specific and important events to handle. These are all cases where a program running within an error not detectable at compile time.
Such situations may be due, for example, an input incorrectly (or not in accordance with requests) from the user or, perhaps the most insidious, the state of the computer when they run the program. Generated is in fact an 'exception, for example, if you request to allocate a memory area and this space is not available.
For planning a safe and efficient, thus you need to handle exceptions. It is, in other words, to identify blocks of code you may be experiencing these situations and consider appropriate measures to prevent, even in that case, a program crash.
Concerning in particular the C + + language, used most frequently by far, was also developed a particular idiom, which could perhaps be translated as "dialect" (a particular version of the language) capable of ensuring their better management of exceptions, notably as regards the assignment operators. This is the copy and swap idiom.
In essence, one of the types of education which tends to create more problems for the management of exceptions is represented by the assignments. It is, among other things, statements that are used with great frequency.
Reference is made each time that award, in fact, it assigns the value of a variable. In the most significant (and very common) or in case of a variable is dynamically allocated (and thus, we can say, able to adapt to the needs of the user during program execution), the 'assignment is consists of two primary phases.
First of all you need to deallocate or free the resource currently in use (ie the current data) and then allocate the new resource (the new data given).
If, however, once released the resource, for some reason related to the particular situation in which the program runs, you are not able to get the new resource, the program itself is in an inconsistent state. It is located in a state that is not provided, from which you can not go out except with an unexpected execution.
Using the dialect Copy And Swap Idiom, you can precede the resource request verification that the resource is available, so this type of exception is handled effectively, for example by printing an error message such as "Resource not available" and unable to continue Then run the program. We evaluate how you can translate this procedure code.
| |
Flash MX (Advanced)
Become a designer of Web sites from 29 €. |
| |
OpenOffice (Ebook)
The open-source software for managing the office work. Just 25 €. |
| |
Photoshop (Course)
Web graphics and photo editing with the popular Adobe Photoshop. From 49 €. |