Dart Exceptions: Catch Clause

Dart Exceptions: Catch Clause

ยท

1 min read

In earlier we have seen that Exception Handling using try and on clause where we know that which types of the error can occurs .

But in many case we do not know which types of Exception can occur our program, at that time we use Catch Clause.

We can pass one or two parameter in catch (). In this first one is the exception object which was thrown and second one is StackTrack object.

void main()
{
  try{
    int x= 5 ~/ 0;
    print("The x valuse is $x");

  }
  catch(e , s)
  {
    print("Excepation : $e");
    print(s);
  }
}

Here, we have pass two parameter in on catch which is " e " and " s " , where " e " print exception and " s " print StackTrack, we can see in output like #0 ,#1, #2, #3

ย