www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Exceptions on Windows being "swallowed"

reply cartland <example example.com> writes:
Trying out exception handling. When an exception occurs, program 
seems to just exit.

dub -a x86_mscoff

Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for 
x86, x86_mscoff.
x ~master: target for configuration "application" is up to date.
To force a rebuild of up-to-date targets, run again with --force.
Running .\x.exe
Program exited with code -532414463

-------
//from https://dlang.org/spec/statement.html#try-statement
import std.stdio;
int main(){
     try    {
         try   {
             throw new Exception("first");
         } finally  {
             writeln("finally");
             throw new Exception("second");
         }
     } catch (Exception e)    {
         writeln("catch %s", e.msg);
     }
     writeln("done");
     return 0;
}
-----------
Nov 26 2019
next sibling parent reply Mike Parker <aldacron gmail.com> writes:
On Wednesday, 27 November 2019 at 02:48:53 UTC, cartland wrote:
 Trying out exception handling. When an exception occurs, 
 program seems to just exit.

 dub -a x86_mscoff
I compiled it with dmd and ran it directly from the command line and it worked fine: C:\dev\D\scratch>ex finally catch %sfirst done Did you try that? And do you have the MS linker installed or are you using the lld that ships with DMD? Two things regarding your code: writeln does no formatting. You want writefln for that. But with writeln, you can provide multiple string arguments and they will be concatenated into the final output, like this: writeln("catch ", e.msg); Also, you don't need the `int main` signature if you don't actually need the return value to signify anyting: void main() { }} is just fine.
Nov 26 2019
parent reply cartland <example example.com> writes:
On Wednesday, 27 November 2019 at 04:11:44 UTC, Mike Parker wrote:
 On Wednesday, 27 November 2019 at 02:48:53 UTC, cartland wrote:
 Trying out exception handling. When an exception occurs, 
 program seems to just exit.

 dub -a x86_mscoff
I compiled it with dmd and ran it directly from the command line and it worked fine:
hmmm!
 Did you try that? And do you have the MS linker installed or 
 are you using the lld that ships with DMD?
No MS installed. Just using DMD. ----- dub -a x86_mscoff --force -v : Generating using build Configuring dependent x, deps: Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for x86, x86_mscoff. x ~master: building configuration "application"... C:\D\dmd2\windows\bin\dmd.exe -m32mscoff -c -of.dub\build\application-debug-windows-x86.x86_mscoff-dmd_2089-6ACE9C396DEB2C31A2 9A4E275587962\x.obj -debug -g -w -version=Have_x -Isource source\app.d -vcolumns Linking... C:\D\dmd2\windows\bin\dmd.exe -of.dub\build\application-debug-windows-x86.x86_mscoff-dmd_2089-6ACE9C396DEB2C31A2 9A4E275587962\x.exe .dub\build\application-debug-windows-x86.x86_mscoff-dmd_2089-6ACE9C396DEB2C31A2 9A4E275587962\x.obj -m32mscoff -g Copying target from C:\tmp\x\.dub\build\application-debug-windows-x86.x86_mscoff-dmd_2089-6ACE9C396DEB2C31A2 9A4E275587962\x.exe to C:\tmp\x Running .\x.exe Program exited with code -532414463 --------
 Two things regarding your code:
Thanks for the advice. It was just a quick cut and paste from the sample code to test.
Nov 26 2019
next sibling parent cartland <example example.com> writes:
This works (once I installed Microsoft Visual C++ 2010  x64 
Redistributable) :

dub --force -v

Seems the issue is with "x86_mscoff"

--------------
:
Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for 
x86_64.
x ~master: building configuration "application"...
C:\D\dmd2\windows\bin\dmd.exe -m64 -c 
-of.dub\build\application-debug-windows-x86_64-dmd_2089-1DF706DBEDBB125C87
4D2CAFEE4D94A\x.obj -debug -g -w -version=Have_x -Isource source\app.d -vcolumns
Linking...
C:\D\dmd2\windows\bin\dmd.exe 
-of.dub\build\application-debug-windows-x86_64-dmd_2089-1DF706DBEDBB125C87
4D2CAFEE4D94A\x.exe .dub\build\application-debug-windows-x86_64-dmd_2089-1DF706DBEDBB125C87
4D2CAFEE4D94A\x.obj -m64 -g
Copying target from 
C:\tmp\x\.dub\build\application-debug-windows-x86_64-dmd_2089-1DF706DBEDBB125C87
4D2CAFEE4D94A\x.exe to C:\tmp\x
Running .\x.exe
finally
catch %sfirst
done
------------
Nov 26 2019
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
On Wednesday, 27 November 2019 at 05:15:10 UTC, cartland wrote:
 
 No MS installed. Just using DMD.
 -----
 dub -a x86_mscoff --force -v
 :
So please try it without dub dmd -m32mscoff x.d If that works, add some debug flags like dub does: dmd -m32mscoff -debug -g x.d And see what happens.
Nov 26 2019
parent reply cartland <example example.com> writes:
On Wednesday, 27 November 2019 at 05:43:33 UTC, Mike Parker wrote:
 On Wednesday, 27 November 2019 at 05:15:10 UTC, cartland wrote:
 *snip*

 dmd -m32mscoff -debug -g x.d

 And see what happens.
No difference between "dmd -m32mscoff -debug -g x.d" and "dmd -m32mscoff x.d" -------- C:\tmp\x>dmd -m32mscoff -debug -g x.d C:\tmp\x>x hello C:\tmp\x>dmd x.d C:\tmp\x>x hello finally catch first done ---------- x.d contents -------- import std.stdio; void main() { writeln("hello"); try { try { throw new Exception("first"); } finally{ writeln("finally"); throw new Exception("second"); } } catch (Exception e) { writeln("catch ", e.msg); } writeln("done"); } -----------
Nov 26 2019
parent Rainer Schuetze <r.sagitario gmx.de> writes:
On 27/11/2019 06:55, cartland wrote:
 On Wednesday, 27 November 2019 at 05:43:33 UTC, Mike Parker wrote:
 On Wednesday, 27 November 2019 at 05:15:10 UTC, cartland wrote:
 *snip*

 dmd -m32mscoff -debug -g x.d

 And see what happens.
No difference between "dmd -m32mscoff -debug -g x.d" and "dmd -m32mscoff x.d" -------- C:\tmp\x>dmd -m32mscoff -debug -g x.d C:\tmp\x>x hello C:\tmp\x>dmd x.d C:\tmp\x>x hello finally catch first done ---------- x.d contents -------- import std.stdio; void main() {     writeln("hello");     try {         try {             throw new Exception("first");         } finally{             writeln("finally");             throw new Exception("second");         }     } catch (Exception e) {         writeln("catch ", e.msg);     }     writeln("done"); } -----------
In a debugger, I get: Unhandled exception at 0x004010EF in x.exe: 0xC00001A5: An invalid exception handler routine has been detected (parameters: 0x00000001). This seems to happen when lld is used instead of the Microsoft linker. Maybe related: https://bugs.llvm.org/show_bug.cgi?id=42221 Using lld from LLVM 9 spits out errors "not compatible with SEH", but links using /SAFESEH:NO. The resulting executable then works. I have created an issue: https://issues.dlang.org/show_bug.cgi?id=20421
Nov 26 2019
prev sibling parent DanielG <simpletangent gmail.com> writes:
Not sure if related to OP's issue, but quite often on Windows I 
get mystery crashes with no stack trace, so I typically use 
WinDbg Preview (modern version of WinDbg) to locate the problem. 
Seems to work every time.
Nov 27 2019