Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2002-01

a 'rises' keyword proposal

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Aleksey V. Vaneev

Hello,

Maybe my suggestion is outdated, but is it possible to add some keyword like 'rises' to function/method/procedure declarations?

This way sources will become more self-documenting and much more predictable. In fact in C++ something like that (although, in a not very useful manner) already presents and I've always used it when programmed in C++.

So, by default when 'rises' keyword is not declared in function declaration, no exception drops are allowed in that function. Along with that inside such function no other function calls that drop exceptions are allowed. This functionality of course will require some major update in user sources and some updates in RTL sources (only those functions that rise exceptions like EOutOfMemory), so I think it will be wise to add some command-line option to disable such behaviour or vise versa.

Please, this is very essential I think.

Best regards,
Aleksey

Reply by email

Michael Van Canneyt
to Aleksey V. Vaneev
Aleksey V. Vaneev wrote 12 lines
Hello, Maybe my suggestion is outdated, but is it possible to add some keyword like 'rises' to function/method/procedure declarations? This way sources will become more self-documenting and much more predictable. In fact in C++ something like that (although, in a not very useful manner) already presents and I've always used it when programmed in C++. So, by default when 'rises' keyword is not declared in function declaration, no exception drops are allowed in that function.

I don't see how this can be useful in practice:

1. This would mean that 99,99 % of all functions need it: The memory manager can raise an exception, so almost all functions can implicitly raise an exception, expecially if they use ansistrings.

Function A uses function B; Function B MAY use ansistrings (depending on $H+), but function A is not aware of this. So, A can give rise to an exception, but has no way of knowing this.

2. As pointed out: If a function uses a string, it depends on the setting of the $H+ flag.

3. If you don't use the sysutils unit, no exceptions will be generated for system errors. If you do, then they are generated. It is hard to predict the usage of this unit.

So, while the idea is good in theory, I think that this would be very impractical. You should always expect ANY function to be able to raise an exception.

Michael.

Reply by email