RejectedSoftware Forums

Sign up

Unable to throw exceptions in the delegate called by listenTCP function

Binary file produced from the following code works perfectly on one computer (Windows 8 x64) and crashes on another (Windows Server 2012 R2 Standard x64):

import std.stdio;

import vibe.vibe;

void new_request(TCPConnection conn)
{
  writeln("before");

  try
  {
    throw new Exception("Exception");
  }
  catch (Throwable ex)
  {
    writeln(ex.msg);
  }

  writeln("after");
}

void main()
{
  auto f = toDelegate(&new_request);
  listenTCP(1605, f);
  runEventLoop();
}

Output on Windows 8 x64

before
Exception
after

Output on Windows Server 2012 R2 Standard x64

before

And then crash.

It seems that I can't throw any exception in the delegate called by listenTCP function on some computers.

Is it a well-known behavior? Is it a bug?

I'm using DMD 2.068.2, DUB 0.9.24 and vibe.d 0.7.24.

dub.json looks like this:

{
    "name": "vibe_helper",
    "dependencies": {
        "vibe-d": "==0.7.24"
    },
    "versions": ["VibeCustomMain"]
}

Throwing and catching exceptions anywhere else (in the main thread or in the thread created via Thread class) works as expected.

Thanks in advance.

Re: Unable to throw exceptions in the delegate called by listenTCP function

It can be reproduced via the following code too:

import std.stdio;

import vibe.vibe;

void foo()
{
  writeln("before");

  try
  {
    throw new Exception("Exception");
  }
  catch (Throwable ex)
  {
    writeln(ex.msg);
  }

  writeln("after");
}

void main()
{
  auto f = toDelegate(&foo);
  runTask(f);
  runEventLoop();
}

Re: Unable to throw exceptions in the delegate called by listenTCP function

It seems that this behavior related to Fiber class:

import std.stdio;
import core.thread;

void foo()
{
  writeln("before");

  try
  {
    throw new Exception("Exception");
  }
  catch (Throwable ex)
  {
    writeln(ex.msg);
  }

  writeln("after");
}

void main()
{
  Fiber fiber = new Fiber(&foo);
  fiber.call();
}

Re: Unable to throw exceptions in the delegate called by listenTCP function

Am 04.11.2015 um 15:16 schrieb Nikita:

It seems that this behavior related to Fiber class:

import std.stdio;
import core.thread;

void foo()
{
   writeln("before");

   try
   {
     throw new Exception("Exception");
   }
   catch (Throwable ex)
   {
     writeln(ex.msg);
   }

   writeln("after");
}

void main()
{
   Fiber fiber = new Fiber(&foo);
   fiber.call();
}

There is an open ticket for DMD:
https://issues.dlang.org/show_bug.cgi?id=13821

I also often get crashes on my Win8 system, but I didn't manage to take
the time to reduce this to a minimal test case. It doesn't fail for the
simple ones above.