Why does scope(success) have to use exceptions?

Maxim Fomin maxim at maxim-fomin.ru
Thu Jan 17 05:45:25 PST 2013


On Thursday, 17 January 2013 at 13:05:00 UTC, deadalnix wrote:
> On Thursday, 17 January 2013 at 12:15:07 UTC, Maxim Fomin wrote:
>> On linux, segfaults can be translated into exceptions using 
>> this module 
>> (https://github.com/D-Programming-Language/druntime/blob/master/src/etc/linux/memoryerror.d) 
>> however I do not know how to use it - I get linker errors.
>>
>
> Can you provide a sample code and the error message ?

import etc.linux.memoryerror;
import core.stdc.stdio : printf;


class A { int x; }

void main()
{
	A a;
	try
	{
		a.x = 0;
	}
	catch(NullPointerError er)
	{
		printf("catched\n");
	}
}

main.o:(.data+0xd0): undefined reference to 
`_D3etc5linux11memoryerror16NullPointerError7__ClassZ'
collect2: error: ld returned 1 exit status
--- errorlevel 1

InvalidPointerError does not work either.

Perhaps this is a wrong usage, but I do not see any spec at 
dlang.org or inside source file.


More information about the Digitalmars-d mailing list