Thread overview
goto finally - fail. Why?
19 hours ago
Brother Bill
19 hours ago
monkyyy
18 hours ago
Brother Bill
19 hours ago

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;
}

19 hours ago

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

18 hours ago

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

That's it! It's works exactly like C# too. Same 'finally' keyword.