Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

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 :: mp3 player with swift iOS & macOS 
Swift :: So, because promart depends on both flutter_test from sdk and freezed ^1.1.1, version solving failed. [ ] FINE: Exception type: SolveFailure 
Swift :: Swift Function with Return Multiple Values 
Swift :: Swift continue Statement With for Loop 
Swift :: swift class init 
Swift :: load plist swift 
Swift :: swift toggle on change 
Swift :: underline text in storyboard xcode 
Ruby :: how to match email in regex in ruby 
Ruby :: rails undo scaffold 
Ruby :: ruby filename from path 
Ruby :: ruby refinement import dynamic methods 
Ruby :: getting wanked off by ruby 
Ruby :: ruby replace certain character 
Ruby :: ruby check if exists 
Ruby :: ruby array has element 
Ruby :: rails change column type string to integer 
Ruby :: rails validate email 
Ruby :: autoload lib directory rails 
Ruby :: ruby global variable 
Ruby :: Rails.root 
Ruby :: rails logger stdout 
Ruby :: log rails 
Ruby :: ruby open file and append 
Ruby :: Rails public folder items not available in production 
Ruby :: check validate url ruby 
Ruby :: how to remove last element from array in ruby 
Ruby :: user.destroy all except one rails 
Ruby :: simple form change id 
Ruby :: find_by column name rails route 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =