Skip to main content

Command Palette

Search for a command to run...

Dart Error Handling

Published
1 min read
Dart Error Handling
V

"Hello World, I'm Vinit Mepani, a coding virtuoso driven by passion, fueled by curiosity, and always poised to conquer challenges. Picture me as a digital explorer, navigating through the vast realms of code, forever in pursuit of innovation.

In the enchanting kingdom of algorithms and syntax, I wield my keyboard as a magical wand, casting spells of logic and crafting solutions to digital enigmas. With each line of code, I embark on an odyssey of learning, embracing the ever-evolving landscape of technology.

Eager to decode the secrets of the programming universe, I see challenges not as obstacles but as thrilling quests, opportunities to push boundaries and uncover new dimensions in the realm of possibilities.

In this symphony of zeros and ones, I am Vinit Mepani, a coder by passion, an adventurer in the digital wilderness, and a seeker of knowledge in the enchanting world of code. Join me on this quest, and let's create digital wonders together!"

Error handling in Dart involves handling exceptions and errors when the program encounters an unexpected situation.

This is crucial to make the program robust and user-friendly.

Dart uses 'try-catch' blocks to catch exceptions, with the 'on' keyword for specific types and 'catch' for all types.

Here , I am attaching one example of try and catch block with on keyword.

void main()
{
  String userInput = "3,14";
  try{
      double num = double.parse(userInput);
      print("Squre value is $userInput * $userInput");
  }on FormatException catch (e){
    print("You have inavalid input , Enter valid value and try agian");
    print(e);
  }
  catch(e)
  {
    print("Somthing wrong happend in your output");
    print(e);
  }
}

In the above example you can see that we have use try , catch and on method to handle the error when it throw runtime.

More from this blog

Vinit Mepani (Flutter Developer)

270 posts

"Vinit Mepani, passionate coder! Dive into my Dart and Flutter journey on the blog. Let's master these tech wonders together. Happy coding! 🚀"

Dart Error Handling