Question/suggestion about exceptions
BCS
BCS at pathlink.com
Mon Oct 23 17:11:04 PDT 2006
Graham St Jack wrote:
> Is there a way to automatically keep track of what exceptions may be
> thrown by a function or method? Ideally, what I am looking for is
> something like Java's "throws" keyword, but I would be happy with almost
> anything.
>
> It is way too hard to develop reliable code of any size that uses
> exceptions extensively, because as things change, you lose track of what
> exceptions are thrown from where. Some sort of compiler support would
> make this a lot easier.
>
> What I had in mind was an optional compiler warning and a new "throws"
> keyword. The compiler would (optionally) issue a warning if a function
> or method can throw an exception that it hasn't declared that it
> "throws". With this assistance, it becomes is easy to keep track of what
> can be thrown from where. Making it a warning and optional stops it from
> breaking existing code, and makes quick code hacks easy to write still.
>
> Thoughts?
I would think You could be able to get most of that from a code analysis
tool that dumps the type of all throw statements and a function call
tree. A a "linker" with a little DDoc like markup and you'd have quite a
tool.
OTOH this:
int foo(int function() fn)
{
return fn();
}
could throw anything, as could this:
int foo(Error err)
{
throw err;
}
so some odd cases might not be so clean.
More information about the Digitalmars-d
mailing list