What is nothrow for?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Apr 28 07:01:04 PDT 2008
"Janice Caron" wrote
> On 26/04/2008, Ameer Armaly wrote:
>> It seems to me that the compiler could figure out whether or not a
>> function
>> throws exceptions and act accordingly;
>
> Without the nothrow keyword, the only way it could do that is by
> checking not only the function itself, but the function bodies of all
> functions called by the function, and so, recursively, forever.
Enter your algorithmic friend, memoization :) The compiler could store
attributes with the functions as they are compiled, marking ones which don't
throw exceptions and ones which are pure, etc. in the object files.
The only issue then is if you are a developer and you desire a function to
be a nothrow, it must be marked by the developer. Otherwise it's like
inlining. You never know which functions will be marked nothrow/pure and
which ones will not. It also becomes a question of maintainability, if one
makes a change in a nothrow function that throws an exception, this is no
good for dynamic libraries, who may depend on it keeping the nothrow status.
-Steve
More information about the Digitalmars-d
mailing list