xxxxxxxxxx
try {
final db = await database;
await db.insert(
_tableName,
message,
conflictAlgorithm: ConflictAlgorithm.replace,
);
} catch (e) {
print('Failed to add message: $e');
}
xxxxxxxxxx
try {
breedMoreLlamas();
} on OutOfLlamasException { // A specific exception
buyMoreLlamas();
} on Exception catch (e) { // Anything else that is an exception
print('Unknown exception: $e');
} catch (e) { // No specified type, handles all
print('Something really unknown: $e');
} finally { // Always clean up, even if case of exception
cleanLlamaStalls();
}
xxxxxxxxxx
try {
// code that might throw an exception
}
on Exception1 {
// code for handling exception
}
catch Exception2 {
// code for handling exception
}