[Mono-list] exceptions are not thrown from ThreadPool'ed thread objects?

sarvesh sarvesh <sarvesh.com@gmail.com>
Tue, 19 Oct 2004 13:39:06 +0530


That's the right behaviour it should not get thrown up to say the Main
Method. But what is interesting with the code is it should throw an
UnHandled exception. The code does throw unhandled exception with ms
.net but not with mono ??



On Tue, 19 Oct 2004 00:58:26 -0700, gennady wexler <adyler@winisp.net> wrote:
> has anyone noticed this problem? that is if you have a ThreadPool'ed thread
> object created, any exception thrown inside of that thread will not be
> rethrown up at all. I ran into this accidentally while developing some
> performance code..
> 
> here's an example, could someone please try this with .net compiler/runtime?
> 
> if you just compile and run it, the exception in _ThreadProc does not get
> thrown.
> 
> now, if you uncomment regular thread definition below "ThreadPool" - you
> will get "exception 2" get thrown.
> 
> any ideas? is this expected? I hope not...
> 
> using System;
> using System.Threading;
> 
> public class main {
>         static void Main() {
>                 // this will not throw exception 1 (seems to be a bug?)
>                 ThreadPool.UnsafeQueueUserWorkItem(new
>                         WaitCallback(_ThreadProc), null);
> 
>                 // uncomment this to thrown exception 2 (as expected)
>                 // new Thread(new ThreadStart(_ThreadProc2)).Start();
> 
>                 Thread.Sleep(90000);
>         }
> 
>         private static void _ThreadProc(Object state) {
>                 throw new Exception("exception 1");
>         }
> 
>         private static void _ThreadProc2() {
>                 throw new Exception("exception 2");
>         }
> }
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>