// throws or raises and exceptionthrowIntegerDivisionByZeroException();// You can also throw arbitrary objectsthrow"Product out of stock!";
Catch
try{intc=3/0;print(c);}onIntegerDivisionByZeroException{// A specific exceptionprint('Can not divide integer by 0.')}onExceptioncatch(e){// Anything else that is an exceptionprint('Unknown exception: $e');}catch(e){// No specified type, handles allprint('Something really unknown: $e');}
Finally
// To ensure that some code runs whether or not an exception is throwntry{cookFood();}catch(e){print('Error: $e');// Handle the exception first.}finally{cleanKitchen();// Then clean up.}