Skip to main content

New site for Dart news and articles

For the latest Dart news, visit our new blog at  https://medium.com/dartlang .

New try/catch syntax ready to use

Posted by Kasper Lund


We're very close to being able to turn off the support for the old
try-catch syntax. Early next week attempts to use the old syntax will
lead to compile-time errors. The new syntax already works today so now
would be a fantastic time to update your code.

The old syntax like:

   try { ... } catch (var e) { ... }
   try { ... } catch (final e) { ... }
   try { ... } catch (T e) { ... }
   try { ... } catch (final T e) { ... }

translates to new syntax like this:

   try { ... } catch (e) { ... }
   try { ... } catch (e) { ... }
   try { ... } on T catch (e) { ... }
   try { ... } on T catch (e) { ... }


and the local variable introduced to hold the reference to the caught
exception (e) is implicitly final in all cases.

Why did we make this change? The M1 Updates article explains it best.