June 03, 2013 Re: Exception isn't thrown as expected | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandr Druzhinin | On 06/03/2013 12:30 AM, Alexandr Druzhinin wrote: > if child thread throws an exception, > should it print some diagnostic message to clear that it crashed or no? No, the parent does not know about such a termination. These are the following options that I know of: 1) The exceptions can be caught by the child and sent to the owner explicitly as a special message that both understand. Or the exception can directly be passed as a message: 2) try { // ... } catch (shared(Exception) exc) { owner.send(exc); }, The owner receives that message just like a message: receive( // ... (shared(Exception) exc) { throw exc; }); The code above re-throws the child's exception in the owner's context but it could do anything else as well. There are also the following exceptions that are related to std.concurrency: * MessageMismatch * OwnerTerminated * LinkTerminated * MailboxFull * PriorityMessageException I have some examples here: http://ddili.org/ders/d.en/concurrency.html Ali |
June 04, 2013 Re: Exception isn't thrown as expected | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandr Druzhinin | 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?
Rephrase my question - I have a function getObjectType, that throws an exception. Unittest is ok. But in more complex use case, this function doesn't throw exception and just hangs up. If I brace the function call by try/catch then an exception is throw again. But I guess exception have to be thrown in any case.
|
June 04, 2013 Re: Exception isn't thrown as expected | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandr Druzhinin | 04.06.2013 19:18, Alexandr Druzhinin пишет: > 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? > > Rephrase my question - I have a function getObjectType, that throws an > exception. Unittest is ok. But in more complex use case, this function > doesn't throw exception and just hangs up. If I brace the function call > by try/catch then an exception is throw again. But I guess exception > have to be thrown in any case. Oh, no.. If I do ... try { auto foo = some_class_instance.getObjectType(); } catch(Throwable t) { writeln(t.msg); // print exception, no hanging throw t; // hangs again } ... all happens in the main thread. |
Copyright © 1999-2021 by the D Language Foundation