Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Eiffel (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Exception handling=== [[Exception handling]] in Eiffel is based on the principles of design by contract. For example, an exception occurs when a routine's caller fails to satisfy a precondition, or when a routine cannot ensure a promised postcondition. In Eiffel, exception handling is not used for [[control flow]] or to correct data-input mistakes. An Eiffel exception handler is defined using the {{mono|rescue}} keyword. Within the {{mono|rescue}} section, the {{mono|retry}} keyword executes the routine again. For example, the following routine tracks the number of attempts at executing the routine, and only retries a certain number of times: <syntaxhighlight lang="eiffel"> connect_to_server (server: SOCKET) -- Connect to a server or give up after 10 attempts. require server /= Void and then server.address /= Void local attempts: INTEGER do server.connect ensure connected: server.is_connected rescue if attempts < 10 then attempts := attempts + 1 retry end end </syntaxhighlight> This example is arguably flawed for anything but the simplest programs, however, because connection failure is to be expected. For most programs a routine name like {{mono|attempt_connecting_to_server}} would be better, and the postcondition would not promise a connection, leaving it up to the caller to take appropriate steps if the connection was not opened.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)