Jump to page: 1 2
Thread overview
Exception isn't thrown as expected
May 31, 2013
Alexandr Druzhinin
May 31, 2013
Adam D. Ruppe
May 31, 2013
Alexandr Druzhinin
May 31, 2013
Marco Leise
May 31, 2013
Alexandr Druzhinin
May 31, 2013
Marco Leise
Jun 03, 2013
Alexandr Druzhinin
Jun 03, 2013
Ali Çehreli
Jun 03, 2013
Alexandr Druzhinin
Jun 03, 2013
Jonathan M Davis
Jun 03, 2013
Ali Çehreli
Jun 04, 2013
Alexandr Druzhinin
Jun 04, 2013
Alexandr Druzhinin
May 31, 2013
Hello
I have code like this:

class SomeClass {
ubyte[] data_;

...

    auto getObjectType() const {
    	if(data_ is null) {
    		writeln("throwing");
    		throw new Exception("Here the exception should be thrown!");
    	}
        KeyHeaderHelper value_header;
        value_header.ptr_ = cast(ubyte*) data_.ptr;
        return value_header.object_type;
    }
}

When data_ is null the application just prints "throwing" and hangs up without an exception throwing. I don't know how to handle this. May be I did something wrong? If so then what?
May 31, 2013
three questions come to mind:

1) what operating system and 32 bit or 64 bit?
2) what D compiler?
3) are you sure you didn't catch the exception somewhere up the chain and silence the message that way?
May 31, 2013
31.05.2013 8:59, Adam D. Ruppe пишет:
> three questions come to mind:
>
> 1) what operating system and 32 bit or 64 bit?
> 2) what D compiler?
> 3) are you sure you didn't catch the exception somewhere up the chain
> and silence the message that way?
1) win7 64
2) dmd 32
3) I don't catch explicitly. To ensure it isn't catch some way implicitly I just throw Exception without condition and it is thrown as expected
auto getObjectType() const {
        throw new Exception("Here the exception should be thrown!"); // works as expected
        KeyHeaderHelper value_header;
        value_header.ptr_ = cast(ubyte*) data_.ptr;
        return value_header.object_type; // if data isn't null it hangs up here
    }

moreover, when I provide data_ always have some length, the application starts hangin at return operator. I've met something like this behaviour (I mean silent hanging up) earlier working with std.concurrency, but I found some workaround. Now I dont know what to do.
May 31, 2013
Am Fri, 31 May 2013 10:26:49 +0700
schrieb Alexandr Druzhinin <drug2004@bk.ru>:

> 31.05.2013 8:59, Adam D. Ruppe пишет:
> > three questions come to mind:
> >
> > 1) what operating system and 32 bit or 64 bit?
> > 2) what D compiler?
> > 3) are you sure you didn't catch the exception somewhere up the chain
> > and silence the message that way?
> 1) win7 64
> 2) dmd 32
> 3) I don't catch explicitly. To ensure it isn't catch some way
> implicitly I just throw Exception without condition and it is thrown as
> expected
> auto getObjectType() const {
>          throw new Exception("Here the exception should be thrown!"); //
> works as expected
>          KeyHeaderHelper value_header;
>          value_header.ptr_ = cast(ubyte*) data_.ptr;
>          return value_header.object_type; // if data isn't null it hangs
> up here
>      }
> 
> moreover, when I provide data_ always have some length, the application starts hangin at return operator. I've met something like this behaviour (I mean silent hanging up) earlier working with std.concurrency, but I found some workaround. Now I dont know what to do.

The code that you haven't shown reads:

  int main(string[] args) {
      SomeClass c;
      auto t = c.getObjectType();
      return 0;
  }

You have to fix that!

-- 
Marco

May 31, 2013
31.05.2013 10:49, Marco Leise пишет:
>
> The code that you haven't shown reads:
>
>    int main(string[] args) {
>        SomeClass c;
>        auto t = c.getObjectType();
>        return 0;
>    }
>
> You have to fix that!
>
You mean I didn't initialize c? If even so, it should throw an exception, no hanging, I think. Nevertheless, a class instance is correct. I'll try to reduce code.
May 31, 2013
Am Fri, 31 May 2013 10:59:09 +0700
schrieb Alexandr Druzhinin <drug2004@bk.ru>:

> You mean I didn't initialize c?

It was a wild guess, that you might come from C++ and write

  SomeClass c;

which would be an instance of that class in C++, but a null reference in D. As you said you only get the hanging when you compare the this.data_ field with null it could have made some sense.

> If even so, it should throw an exception, no hanging, I think. Nevertheless, a class instance is correct. I'll try to reduce code.

Others may know for sure, but I think D only throws NullPointerExceptions in @safe code and leaves it to the operating system to stop your program in other cases. So on Linux it would SEGFAULT and on Windows you probably get a message box. But yeah... that still doesn't explain the hanging :D

-- 
Marco

June 03, 2013
31.05.2013 8:56, Alexandr Druzhinin пишет:
> Hello
> I have code like this:
>
> class SomeClass {
> ubyte[] data_;
>
> ...
>
>      auto getObjectType() const {
>          if(data_ is null) {
>              writeln("throwing");
>              throw new Exception("Here the exception should be thrown!");
>          }
>          KeyHeaderHelper value_header;
>          value_header.ptr_ = cast(ubyte*) data_.ptr;
>          return value_header.object_type;
>      }
> }
>
> When data_ is null the application just prints "throwing" and hangs up
> without an exception throwing. I don't know how to handle this. May be I
> did something wrong? If so then what?
can't reduce code enough, but I found that after calling std.concurrency.spawn() template - exceptions stop throwing, but if I add little delay in beginning of spawned thread about 100 ms - it'd works again and exceptions would be thrown again... :(
June 03, 2013
On 06/02/2013 08:23 PM, Alexandr Druzhinin wrote:

> I found that after calling
> std.concurrency.spawn() template - exceptions stop throwing, but if I
> add little delay in beginning of spawned thread about 100 ms - it'd
> works again and exceptions would be thrown again... :(

Is the exception thrown by a child thread? If so, perhaps that is causing the child to terminate. Also, the parent cannot catch a child's exception automatically.

Ali

June 03, 2013
03.06.2013 12:26, Ali Çehreli пишет:
> On 06/02/2013 08:23 PM, Alexandr Druzhinin wrote:
>
>  > I found that after calling
>  > std.concurrency.spawn() template - exceptions stop throwing, but if I
>  > add little delay in beginning of spawned thread about 100 ms - it'd
>  > works again and exceptions would be thrown again... :(
>
> Is the exception thrown by a child thread? If so, perhaps that is
> causing the child to terminate. Also, the parent cannot catch a child's
> exception automatically.
>
> Ali
>
no, the main thread do it. But even if child thread throws an exception, should it print some diagnostic message to clear that it crashed or no? Because my app just hangs up and nothing more, no message, no complaints, nothing.
June 03, 2013
On Monday, June 03, 2013 14:30:48 Alexandr Druzhinin wrote:
> 03.06.2013 12:26, Ali Çehreli пишет:
> > On 06/02/2013 08:23 PM, Alexandr Druzhinin wrote:
> >  > I found that after calling
> >  > std.concurrency.spawn() template - exceptions stop throwing, but if I
> >  > add little delay in beginning of spawned thread about 100 ms - it'd
> >  > works again and exceptions would be thrown again... :(
> > 
> > Is the exception thrown by a child thread? If so, perhaps that is causing the child to terminate. Also, the parent cannot catch a child's exception automatically.
> > 
> > Ali
> 
> no, the main thread do it. But even if child thread throws an exception, should it print some diagnostic message to clear that it crashed or no? Because my app just hangs up and nothing more, no message, no complaints, nothing.

It would be simple enough to test, but I don't think that anything informs you of what happened to the child thread. If you try and send a message to it, I think that you get an exception indicating the the thread terminated incorrectly, but I'm not sure. You'd have to test it to see exactly what it does.

- Jonathan M Davis
« First   ‹ Prev
1 2