Saturday, February 18, 2006

 

Dying to exit Eiffel

Someone called Sam asked over on comp.lang.eiffel how one could exit an Eiffel program, similar to how one calls "exit(n)" in C.

I suggested to inherit or insert class EXCEPTIONS, then call feature 'die':

   die (code: INTEGER)
-- Terminate execution with exit status code,
-- without triggering an exception.

llothar commented that the equivalent feature for SmartEiffel was 'die_with_code' from class GENERAL. This puzzled me, because the excerpt that I posted was scraped from the output of the "se short" command - but I remembered that llothar is using a derivative of SmartEiffel 1.1 whereas I had used SmartEiffel 2.2, so I decided to look into this a little more.

It turns out that all recent versions of SmartEiffel (including 1.1 and 2.2) offer both GENERAL.die_with_code and EXCEPTIONS.die, with the implementation of 'die' being a call to 'die_with_code'.

Visual Eiffel and ISE Eiffel also support EXCEPTIONS.die, which is specified by the Eiffel Library Kernel Standard (ELKS) and is also present in the latest drafts of Bertrand Meyer's update to ETL.

So, in this case, we can achieve cross-compiler compatibility by using feature 'die' of class EXCEPTIONS.

Of course, this feature breaks structured programming as it can bypass cleanup code that follows the call to 'die', and it also bypasses any enclosing rescue clauses. Maybe you don't want to use it after all - but that's a different issue.

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?