Advertisement
JordanScripter1337

Math Exceptions

Oct 11th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.41 KB | None | 0 0
  1. import Cocoa
  2. enum MathError:ErrorType{
  3.     case argEmpty
  4. }
  5. func divide(arg0:Double,arg1:Double) throws -> Double{
  6.     if arg0 == 0.00{
  7.         throw MathError.argEmpty
  8.     }else if arg1 == 0{
  9.         throw MathError.argEmpty
  10.     }else{
  11.         return arg0 / arg1
  12.     }
  13. }
  14. do{
  15.     try print(divide(0, arg1: 5))
  16. }catch let exception{
  17.     print("Caught exception: \(exception) (Argument cannot be 0)")
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement