Skip to content

Files

Latest commit

 

History

History
41 lines (34 loc) · 675 Bytes

throw_in_finally.md

File metadata and controls

41 lines (34 loc) · 675 Bytes

Pattern: Throw in finally

Issue: -

Description

Throwing exceptions in finally blocks will inevitably cause unexpected behavior that is hard to debug.

Example of correct code:

class Ok {
 double compliantMethod() {
  var i = 5;
  try {
   i = 1 / 0;
  } catch (e) {
   print(e); // OK
  }
  return i;
 }
}

Example of incorrect code:

class BadThrow {
 double nonCompliantMethod() {
  try {
   print('hello world! ${1 / 0}');
  } catch (e) {
   print(e);
  } finally {
   throw 'Find the hidden error :P'; // LINT
  }
 }
}

Further Reading