www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - goto finally - fail. Why?

reply Brother Bill <brotherbill mail.com> writes:
If change 'finally' to 'finally1' in both places, it compiles and 
runs.
Why does 'finally' break compilation?
Is this a BUG or a FEATURE?

From: Programming in D book, page 511.

Error:
```
c:\dev\D\71 - 
80\c76_1c_c_style_code_not_needed_in_D\source\app.d(12): Error: 
identifier expected following `goto`
         goto finally;
              ^
c:\dev\D\71 - 
80\c76_1c_c_style_code_not_needed_in_D\source\app.d(12): Error: 
found `finally` when expecting `;` following `goto` statement
         goto finally;
              ^
c:\dev\D\71 - 
80\c76_1c_c_style_code_not_needed_in_D\source\app.d(17): Error: 
found `finally` instead of statement
     finally:
     ^
```

source/app.d

```
import std.stdio;

void main() {
	writeln("foo() is: ", foo());
}

// --- C code --
int foo() {
	int error = 42;

	if (error) {
		goto finally;
	}

	error = 86;

	finally:
		 // ... cleanup operations ...
		return error;
}

```
Aug 19
parent reply monkyyy <crazymonkyyy gmail.com> writes:
On Tuesday, 19 August 2025 at 20:38:52 UTC, Brother Bill wrote:
 If change 'finally' to 'finally1' in both places, it compiles 
 and runs.
 Why does 'finally' break compilation?
 Is this a BUG or a FEATURE?

 [...]
its a try-catch keyword
Aug 19
parent Brother Bill <brotherbill mail.com> writes:
On Tuesday, 19 August 2025 at 20:40:47 UTC, monkyyy wrote:
 On Tuesday, 19 August 2025 at 20:38:52 UTC, Brother Bill wrote:
 If change 'finally' to 'finally1' in both places, it compiles 
 and runs.
 Why does 'finally' break compilation?
 Is this a BUG or a FEATURE?

 [...]
its a try-catch keyword
keyword.
Aug 19