Checked vs unchecked exceptions

Moritz Maxeiner via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 28 04:04:58 PDT 2017


On Wednesday, 28 June 2017 at 06:31:40 UTC, Biotronic wrote:
> On Monday, 26 June 2017 at 19:31:53 UTC, Moritz Maxeiner wrote:
>> the good *way* to achieve this result would be the following:
>> - When visiting `startFoo`, the compiler automatically 
>> aggregates all different exceptions it may throw and stores 
>> the resulting set
>> - If `startFoo` is going to be part of a (binary) library and 
>> its symbol is exported, also export its exception set
>> - Improve the compiler's nothrow analysis such that if 
>> startFoo is called in scope S, but all of the exceptions in 
>> its exception set are caught (i.e. can't break out of scope 
>> S), it is treated as nothrow in S.
>> - Enclose the call to `startFoo` in B in a nothrow scope.
>
> So I have this .dll. How do I specify which exceptions it 
> throws?

- Static/Dynamic linking: As said in bullet point two above, the 
exception set would have to be exported (more precise: in such a 
way that it can be loaded again at compile time); there are 
several ways to go about that: Add the exception set (e.g. via 
attributes) to the function declarations in a .di file (which 
could indeed look like checked exception, except that it's auto 
generated), use a separate (binary) file with mangled functions 
names to exception set mapping, etc.
- Dynamic loading: Won't work

One could also make an exception for bodyless functions and allow 
specification of the exception set *only* there, e.g.

---
// Allow "checked exceptions" for stubs only
void foo() throws AException throws BException;
---


More information about the Digitalmars-d mailing list