Is there an exception for access violation on LDC/win64?

realhet real_het at hotmail.com
Mon Apr 13 10:18:17 UTC 2020


Hi,

import std.stdio, std.exception;

void main(){
   class C{
     void foo(){ writeln(123); }
   }

   C c;
   try{
     writeln(1);
     c.foo;        // access violation here
     writeln(2);
   }catch(Throwable t){
     writeln("exception");
   }
   writeln(3);
}

When I run this code (using LDC2 64bit Windows), it silently 
crashes where the access violation happens and returns an 
%ERRORLEVEL% value of -1073741795 (-0x3FFFFFE3).

On the Online DLang Editor I get some more information:
Error: /tmp/onlineapp-cf8e338-8b2478 failed with status: -2
Error: message: Segmentation fault (core dumped)
Error: program received signal 2 (Interrupt)

This is better, but is there a trick to turn these system errors 
to an exception, so I would be able to get the location where it 
crashed in my source code?

The best I've found is this trick for Linux: 
https://forum.dlang.org/post/atxyappczlyvqyalvwzw@forum.dlang.org

That error message would be so usefull, but is there a way to do 
it on windows?


More information about the Digitalmars-d-learn mailing list