Why dont dlang check NullPointer?

via Digitalmars-d digitalmars-d at puremagic.com
Fri Mar 27 00:40:59 PDT 2015


On Friday, 27 March 2015 at 03:46:49 UTC, zhmt wrote:
> 	class A
> 	{
> 		void test()
> 		{
> 			writeln("test");
> 		}
> 	}
>
> 	try
> 	{
> 		A a = null;
> 		a.test();
> 	}catch(Throwable t)
> 	{
> 		writeln(t.msg);
> 	}
>
>
> The code above will not print a exception message, but crashes 
> instead.
>
>
> I dont think this a good choice for most scenes. For example,I 
> developed many modules in my server, and add a new module now. 
> If null exception happens, I hope the server continue running, 
> not crash. If the server continue running, the functions 
> offered by old modules can be used by users, only the new 
> module stop serving.
>
>
>
> In short words, I want to catch something like 
> NullPointerException.
>
> Is this possible?

GCC has the switch -fno-non-call-exceptions, but not sure if GDC 
does. You could ask in the gdc forum?


More information about the Digitalmars-d mailing list