Flutter Tutorial

Exception Handling

// Exception handling
// Try - Catch
// Throws

// tey, catch, throw

void main(){
  printer();
}

void printer(){
  try{
    printHeadline();
  } on MyException {
    print('My Exception');
  } on MachineException {
    print('Machine Exception');
  } catch (e){
    print('Something went wrong : ${e.toString()}');
  }
  printContent();

}

void printHeadline(){
  throw MyException();
  // throw MachineException();
  // throw Exception('Not Printing');
  // print('Print Honey Is a headline');
}

void printContent(){
  print('Print Saad Is a Content');
}

class MyException implements Exception{

  @override
  String toString() {
    return 'This is MyException';
  }

}

class MachineException implements Exception{

  @override
  String toString() {
    return 'This is MachineException';
  }

}


Scroll to Top