Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
November 01, 2010 exceptions thrown by new / object constructor ? | ||||
---|---|---|---|---|
| ||||
What exceptions can be throw by object constructor / new expression? Following code fails to compile because compiler says that both functions foo and bar can throw. class C { nothrow this () {} } nothrow void foo () { auto c = new C; } nothrow void bar () { auto o = new Object; } |
November 01, 2010 Re: exceptions thrown by new / object constructor ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michal Minich | Michal Minich Wrote:
> What exceptions can be throw by object constructor / new expression? Following code fails to compile because compiler says that both functions foo and bar can throw.
>
> class C {
> nothrow this () {}
> }
>
> nothrow void foo () {
> auto c = new C;
> }
>
> nothrow void bar () {
> auto o = new Object;
> }
GC can throw OutOfMemoryException
|
November 01, 2010 Re: exceptions thrown by new / object constructor ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On Mon, 01 Nov 2010 15:17:11 -0400, Kagamin wrote: > Michal Minich Wrote: > >> What exceptions can be throw by object constructor / new expression? Following code fails to compile because compiler says that both functions foo and bar can throw. >> >> class C { >> nothrow this () {} >> } >> >> nothrow void foo () { >> auto c = new C; >> } >> >> nothrow void bar () { >> auto o = new Object; >> } > > GC can throw OutOfMemoryException http://www.digitalmars.com/d/2.0/phobos/std_gc.html in GC docs it says it throw OutOfMemoryException, but shouldn't that be OutOfMemoryError ? Isn't the docs just outdated...? |
November 01, 2010 Re: exceptions thrown by new / object constructor ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michal Minich | I thought there was a Bug report on this, but I guess not. I say report it. Ether it should compile or the compiler should error that a constructor can not be nothrow. |
November 02, 2010 Re: exceptions thrown by new / object constructor ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | Jesse Phillips wrote:
> I thought there was a Bug report on this, but I guess not. I say report it. Ether it should compile or the compiler should error that a constructor can not be nothrow.
This has already been fixed in svn, and will be in the next release. See bug 3020.
nothrow is painful and limited in 2.050, but should be quite usable in 2.051.
|
November 02, 2010 Re: exceptions thrown by new / object constructor ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don | On Tue, 02 Nov 2010 15:58:51 +0100, Don wrote:
> Jesse Phillips wrote:
>> I thought there was a Bug report on this, but I guess not. I say report it. Ether it should compile or the compiler should error that a constructor can not be nothrow.
>
> This has already been fixed in svn, and will be in the next release. See
> bug 3020.
> nothrow is painful and limited in 2.050, but should be quite usable in
> 2.051.
Great! Many thanks! This issue has greatly limited nothrow usage because 'new' is so common.
|
Copyright © 1999-2021 by the D Language Foundation