digitalmars.D - nothrow and Throwable?
- Manu (33/33) Apr 06 So, I've never used an exception before, but I guess there's a first tim...
- Olivier Pisano (3/3) Apr 06 Hello,
- Manu (5/8) Apr 06 Ah, I didn't see Error... but yes, this is my hypothesis, I just wanted ...
- Steven Schveighoffer (3/14) Apr 06 https://www.schveiguy.com/blog/2022/05/comparing-exceptions-and-errors-i...
So, I've never used an exception before, but I guess there's a first time
for everything :P
It seems to be that `Throwable` transcends `nothrow`...
Other than proving code correct-ness, the point of `nothrow` as I see it,
is to inform the compiler that it doesn't have to synthesise unwind tables
for everything in no-throw land... but since Throwable can pass through
`nothrow` territory, how are any RAII objects cleaned up while it unwinds?
void code() nothrow
{
RAII something;
doesntThrow();
// destroy something
}
void doesntThrow() nothrow
{
try
canThrow();
catch (Exception)
{
// catch exceptions from canThrow
}
}
void canThrow()
{
throw new Throwable();
}
I expect that an unwind table should not be generated for code(), and so
`RAII something` should not be tidied up if `doesntThrow` actually does
throw... is that what's going on here?
I guess the idea is that Throwable is intended to never be caught, and so
we don't really care about tidying up since an abort is imminent?
Am I reading this correctly... or is it actually that unwind tables are
just always generated for everything, even `nothrow` things?
Apr 06
Hello, I suppose this is because a nothrow function cannot throw an Exception, but can throw an Error.
Apr 06
Ah, I didn't see Error... but yes, this is my hypothesis, I just wanted to confirm if it's correct. Can I expect unwind tables are not generated for nothrow functions? On Mon, 7 Apr 2025 at 14:06, Olivier Pisano via Digitalmars-d < digitalmars-d puremagic.com> wrote:Hello, I suppose this is because a nothrow function cannot throw an Exception, but can throw an Error.
Apr 06
On Monday, 7 April 2025 at 03:46:08 UTC, Manu wrote:So, I've never used an exception before, but I guess there's a first time for everything :P It seems to be that `Throwable` transcends `nothrow`... Other than proving code correct-ness, the point of `nothrow` as I see it, is to inform the compiler that it doesn't have to synthesise unwind tables for everything in no-throw land... but since Throwable can pass through `nothrow` territory, how are any RAII objects cleaned up while it unwinds?https://www.schveiguy.com/blog/2022/05/comparing-exceptions-and-errors-in-d/ -Steve
Apr 06









Manu <turkeyman gmail.com> 