mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-07 07:12:25 +01:00
Merged 20.11 into trunk documentation
git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@2327 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
[[Property:modification_date|Mon, 10 Sep 2018 09:09:25 GMT]]
|
||||
[[Property:modification_date|Fri, 19 Mar 2021 14:23:47 GMT]]
|
||||
[[Property:publication_date|Mon, 10 Sep 2018 09:09:25 GMT]]
|
||||
[[Property:uuid|B74D374E-895C-4F22-B95F-656BD78ECD03]]
|
||||
[[Property:weight|1000]]
|
||||
[[Property:title|Getting a STRING from a NUMERIC object]]
|
||||
[[Property:link_title|NUMERIC to STRING]]
|
||||
Every class has the `out` method that can be used to get a text version of the object. For a lot of classes, this method returns internal information that is not really useful for the end user. But for every `NUMERIC` class, the `out` method returns a text representation of the number that the `NUMERIC` object represents.
|
||||
== <code lang="eiffel">NUMERIC</code> to <code lang="eiffel">STRING</code> ==
|
||||
|
||||
Every class has the <code lang="eiffel">out</code> method that can be used to get a text version of the object. For a lot of classes, this method returns internal information that is not really useful for the end user. But for every <code lang="eiffel">NUMERIC</code> class, the <code lang="eiffel">out</code> method returns a text representation of the number that the <code lang="eiffel">NUMERIC</code> object represents.
|
||||
|
||||
<code>
|
||||
print_integer (a_integer: INTEGER)
|
||||
@@ -14,4 +16,8 @@ Every class has the `out` method that can be used to get a text version of the o
|
||||
end
|
||||
</code>
|
||||
|
||||
Note that for more advanced conversion, you can also use a conversion class like `FORMAT_DOUBLE`.
|
||||
Note that for more advanced conversion, you can also use a conversion class like <code lang="eiffel">FORMAT_DOUBLE</code>.
|
||||
|
||||
== <code lang="eiffel">STRING</code> to <code lang="eiffel">NUMERIC</code> ==
|
||||
|
||||
The reverse conversion is available for all standard numeric types (<code lang="eiffel">INTEGER_8</code>, <code lang="eiffel">INTEGER_16</code>, etc.) using the features <code lang="eiffel">to_integer_8</code>, <code lang="eiffel">to_integer_16</code>, etc. of class <code lang="eiffel">STRING</code>. The string should contain a valid string representation of the corresponding numeric value. This can be checked by calling <code lang="eiffel">is_integer_8</code>, <code lang="eiffel">is_integer_16</code>, etc. before calling the conversion functions.
|
||||
@@ -1,3 +1,5 @@
|
||||
[[Property:modification_date|Thu, 21 Jan 2021 13:42:09 GMT]]
|
||||
[[Property:publication_date|Thu, 21 Jan 2021 13:42:09 GMT]]
|
||||
[[Property:title|ET: Design by Contract (tm), Assertions and Exceptions]]
|
||||
[[Property:weight|-8]]
|
||||
[[Property:uuid|2ef367c9-34d9-d45e-a722-163b39581405]]
|
||||
@@ -323,7 +325,7 @@ Concretely, exceptions may result from the following events: <br/>
|
||||
* Operating system signal:arithmetic overfolow; no memory available for a requested creation or twin -- even after garbage collection has rummaged everything to find some space. (But no C/C++-like "wrong pointer address", which cannot occur thanks to the statically typed nature of Eiffel.)
|
||||
|
||||
|
||||
It is sometimes useful, when handling exceptions in <code>rescue</code> clauses, to ascertain the exact nature of the exception that got the execution there. For this it is suffices to inherit from the Kernel Library class <code>EXCEPTIONS</code>, which provides queries such as <code>exception</code>, giving the code for the last exception, and symbolic names ( [[ET: Other Mechanisms#Constant_attributes|"Constant attributes"]] ) for all such codes, such as <code>No_more_memory</code>. You can then process different exceptions differently by testing <code>exception</code> against various possibilities. The method strongly suggests, however, that exception handling code should remain simple; a complicated algorithm in a <code>rescue</code> clause is usually a sign that the mechanism is being misused. Class <code>EXCEPTIONS</code> also provides various facilities for fine-tuning the exception facilities, such as a procedure <code>raise</code> that will explicitly trigger a "developer exception" with a code that can then be detected and processed. Exception handling helps produce Eiffel software that is not just correct but robust, by planning for cases that should not normally arise, but might out of Murphy's law, and ensuring they do not affect the software's basic safety and simplicity.
|
||||
It is sometimes useful, when handling exceptions in <code>rescue</code> clauses, to ascertain the exact nature of the exception that got the execution there. For this it suffices to inherit from the Kernel Library class <code>EXCEPTIONS</code>, which provides queries such as <code>exception</code>, giving the code for the last exception, and symbolic names ( [[ET: Other Mechanisms#Constant_attributes|"Constant attributes"]] ) for all such codes, such as <code>No_more_memory</code>. You can then process different exceptions differently by testing <code>exception</code> against various possibilities. The method strongly suggests, however, that exception handling code should remain simple; a complicated algorithm in a <code>rescue</code> clause is usually a sign that the mechanism is being misused. Class <code>EXCEPTIONS</code> also provides various facilities for fine-tuning the exception facilities, such as a procedure <code>raise</code> that will explicitly trigger a "developer exception" with a code that can then be detected and processed. Exception handling helps produce Eiffel software that is not just correct but robust, by planning for cases that should not normally arise, but might out of Murphy's law, and ensuring they do not affect the software's basic safety and simplicity.
|
||||
|
||||
==Other applications of Design by Contract™==
|
||||
|
||||
|
||||
Reference in New Issue
Block a user