Why if we return from finally, rethrow from catch not works?

1.4k views Asked by At

Why first case prints : "second level catch" "top level catch"

and second case prints: only "second level catch"?

Difference in finally block.


Future<void> main() async {
  try {
    secondLevelTryCatch();
  } catch (e, s) {
    print("top level catch");
  } 
}

void secondLevelTryCatch() {
  try {
    throw Exception();
  } catch (e, s) {
    print("second level catch");
    rethrow;
  } finally {
 //1 no return
 //2 return;
  }
//3return;
}


why 3 case print: "second level catch" "top level catch"

0

There are 0 answers