Skip to content

Finally block doesn't handle errors from within catch block #11758

Closed
@DartBot

Description

@DartBot

This issue was originally filed by [email protected]


What steps will reproduce the problem?

Type this code in the Editor and run it:

void main() {
  try {
    try {
      throw null;
    } catch(e) {
      throw null;
    } finally {
      print('first');
    }
  } finally {
    print('second');
  }
}

What is the expected output? What do you see instead?

In the VM this produces the following result:

second
Unhandled exception: Throw of null.

In dart2js (try.dartlang.org), it produces this result:

first
second
Uncaught Throw of null.

The two should produce the same output.

The language spec states that:

If an exception is raised during execution of an on-catch clause, this will transfer control to the handler for the finally clause, causing the finally clause to execute in this case as well.

This suggests that the VM implementation has a bug: the error thrown within the catch block does not lead the subsequent finally clause to execute.

What version of the product are you using? On what operating system?

OSX 10.8.4
Dart SDK version 0.5.20.4_r24275

Please provide any additional information below.

This was first reported on StackOverflow:

http://stackoverflow.com/questions/17553334/understanding-exception-handling-mechanism-control-flow-in-dart

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.closed-duplicateClosed in favor of an existing report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions