www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Catching thread creation error

reply tcak <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
In my server program, when a request comes, I create a new thread 
for that.

I put memory limit to program with setrlimit. So, when the limit 
is reached, new thread cannot be created.

I want to tell client back that there is system problem. But 
catching "Throwable" does not suffice for this it seems like. 
Program still breaks and tells that "Error creating thread". Is 
there any normal way to catch this event?
Apr 04 2016
parent tcak <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
On Monday, 4 April 2016 at 20:28:13 UTC, tcak wrote:
 In my server program, when a request comes, I create a new 
 thread for that.

 I put memory limit to program with setrlimit. So, when the 
 limit is reached, new thread cannot be created.

 I want to tell client back that there is system problem. But 
 catching "Throwable" does not suffice for this it seems like. 
 Program still breaks and tells that "Error creating thread". Is 
 there any normal way to catch this event?
Okay. That's my mistake. I was looking at "new Thread" part instead of "start". The "start" function is what allocates memory for the new thread. So, it is the one where try-catch should be used.
Apr 04 2016