Exception_CustomException_Dart

 //Making Custom Exception by User(User defined Exception)

//
void main() {

try
{
checkAge(10);
}
catch(e)
{
print(e.toString());
}
}
void checkAge(int age)
{
if (age < 18) {
throw MyException("This is Eligible for Voting!");
}
}
class MyException implements Exception {

var message = "";
MyException(String msg)
{
this.message = msg;
}
@override
String toString()
{
return message;
}
}

Comments