www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is there an exception for access violation on LDC/win64?

reply realhet <real_het hotmail.com> writes:
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?
Apr 13 2020
parent JN <666total wp.pl> writes:
On Monday, 13 April 2020 at 10:18:17 UTC, realhet wrote:
 Hi,

 import std.stdio, std.exception;

 [...]
Running under the debugger should show you the location of the crash.
Apr 13 2020