Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift do catch

do {
    let sandwich = try makeMeSandwich(kitchen)
} catch let error {
    print(error.localizedDescription)
}
Comment

swift try catch

do {
    // Create audio player object
    audioPlayer = try AVAudioPlayer(contentsOf: soundURL)
            
    // Play the sound
    audioPlayer?.play()
}
catch {
    // Couldn't create audio player object, log the error
    print("Couldn't create the audio player for file (soundFilename)")
}
Comment

Swift Handling Errors Using do-catch Statement

do {
  try division(numerator: 10, denominator: 0)
  ...
}

catch DivisionError.dividedByZero {
  // statement
}
Comment

Swift Error Handling

var numerator = 10
var denominator = 0

// try to divide a number by 0
var result = numerator / denominator // error code
Comment

PREVIOUS NEXT
Code Example
Swift :: swifter apply progress bar 
Swift :: two variable sum in swift 
Swift :: Swift Variable names cannot start with numbers 
Swift :: The Swift pod `qr_code_scanner` depends upon `MTBBarcodeScanner`, which does not define modules 
Swift :: swift out of bound elelemnt 
Swift :: Swift Named Associated Values 
Swift :: table view content size not return correctly 
Swift :: bold world in text swift 
Swift :: ring Desktop, WebAssembly and Mobile Using QTableWidget 
Swift :: Swift continue with while loop 
Swift :: swift function 
Swift :: swift weekday component values 
Swift :: spacing in uitextfield 
Swift :: map vs compactmap in swiftui 
Swift :: how to print body moya swift 
Swift :: function parameters swift 
Swift :: swift how to dereference unsafemutablepointer 
Swift :: Nested Loops in Swift 
Swift :: jsonserialization swift 
Swift :: Arithmetic Operators in Swift 
Swift :: Swift Function with Return Multiple Values 
Swift :: swift variable 
Ruby :: ruby struct 
Ruby :: rails image tag 
Ruby :: travis ci NameError: uninitialized constant SimpleCov 
Ruby :: rails disable cache on dev 
Ruby :: http request ruby 
Ruby :: rails order 
Ruby :: rename column in db rails 
Ruby :: create a new hash from existing hash ruby 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =