Skip to content

Instantly share code, notes, and snippets.

@aabeben
Created December 17, 2019 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aabeben/f898ab9a905b02266af7087dbb21f2fd to your computer and use it in GitHub Desktop.
Save aabeben/f898ab9a905b02266af7087dbb21f2fd to your computer and use it in GitHub Desktop.
Exceptions
// Exceptions
// Untuk membangkitkan sebuah eksepsi, gunakan throw:
if(astonauts == 0){
throw StateError('No astronauts.');
}
// Untuk menangkap sebuah eksepsi, gunakan sebuah pernyataan try dengan on atau
// catch (atau keduanya)
try{
for(var object in flybyObjects){
var description = await File('$object.txt').readAsString();
print(description);
}
} on IOException catch(e){
print('Could not describe object: $e');
} finally{
flybyObjects.clear();
}
// Catatan bahwa kode di atas adalah asynchronous;
// try bekerja baik pada kode synchronous dan kode di dalam fungsi async
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment