www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [dmd 2.066] Is scope with nothrow regression?

reply "NCrashed" <NCrashed gmail.com> writes:
```
void bar()
{
	throw new Exception("");
}

void foo() nothrow
{
	scope(failure) {}
	bar();
}

void main() {}
```
Doesn't compile with 2.066:
```
source/app.d(9): Error: 'app.bar' is not nothrow
source/app.d(6): Error: function 'app.foo' is nothrow yet may 
throw
```
Jul 06 2014
next sibling parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Sunday, 6 July 2014 at 12:31:42 UTC, NCrashed wrote:
 ```
 void bar()
 {
 	throw new Exception("");
 }

 void foo() nothrow
 {
 	scope(failure) {}
 	bar();
 }

 void main() {}
 ```
 Doesn't compile with 2.066:
 ```
 source/app.d(9): Error: 'app.bar' is not nothrow
 source/app.d(6): Error: function 'app.foo' is nothrow yet may 
 throw
 ```
This is not an error. `scope(failure)` doesn't swallow the exceptions it catches, it rethrows them when it's done.
Jul 06 2014
parent "NCrashed" <NCrashed gmail.com> writes:
On Sunday, 6 July 2014 at 13:04:35 UTC, Marc Sch├╝tz wrote:
 On Sunday, 6 July 2014 at 12:31:42 UTC, NCrashed wrote:
 ```
 void bar()
 {
 	throw new Exception("");
 }

 void foo() nothrow
 {
 	scope(failure) {}
 	bar();
 }

 void main() {}
 ```
 Doesn't compile with 2.066:
 ```
 source/app.d(9): Error: 'app.bar' is not nothrow
 source/app.d(6): Error: function 'app.foo' is nothrow yet may 
 throw
 ```
This is not an error. `scope(failure)` doesn't swallow the exceptions it catches, it rethrows them when it's done.
Thank you, I was expecting different behavior for a long time and now will use try-catch instead.
Jul 06 2014
prev sibling parent reply "hane" <han.ehit.suzi.0 gmail.com> writes:
On Sunday, 6 July 2014 at 12:31:42 UTC, NCrashed wrote:
 ```
 void bar()
 {
 	throw new Exception("");
 }

 void foo() nothrow
 {
 	scope(failure) {}
 	bar();
 }

 void main() {}
 ```
 Doesn't compile with 2.066:
 ```
 source/app.d(9): Error: 'app.bar' is not nothrow
 source/app.d(6): Error: function 'app.foo' is nothrow yet may 
 throw
 ```
This is a bug which was already fixed. Instead, you can use this: scope(failure) assert(0); See: https://issues.dlang.org/show_bug.cgi?id=11542
Jul 06 2014
parent "hane" <han.ehit.suzi.0 gmail.com> writes:
On Sunday, 6 July 2014 at 22:03:21 UTC, hane wrote:
 On Sunday, 6 July 2014 at 12:31:42 UTC, NCrashed wrote:
 ```
 void bar()
 {
 	throw new Exception("");
 }

 void foo() nothrow
 {
 	scope(failure) {}
 	bar();
 }

 void main() {}
 ```
 Doesn't compile with 2.066:
 ```
 source/app.d(9): Error: 'app.bar' is not nothrow
 source/app.d(6): Error: function 'app.foo' is nothrow yet may 
 throw
 ```
This is a bug which was already fixed. Instead, you can use this: scope(failure) assert(0); See: https://issues.dlang.org/show_bug.cgi?id=11542
To be exact: "a bug" I said is that scope(failure) { } breaks nothrow checking.
Jul 06 2014