How to handle errors in functions - Swift for Complete Beginners

Поделиться
HTML-код
  • Опубликовано: 13 окт 2024
  • Other videos in the Functions section:
    1. How to reuse code with functions: • How to reuse code with...
    2. How to return values from functions: • How to return values f...
    3. How to return multiple values from functions: • How to return multiple...
    4. How to customize parameter labels: • How to customize param...
    5. How to provide default values for parameters: • How to provide default...
    6. How to handle errors in functions: This video
    7. Summary: Functions: • Summary: Functions - S...
    8. Checkpoint 4: • Checkpoint 4 - Swift f...
    You can find the full set of videos, along with transcriptions, challenges, tests, and more, in my free 100 Days of SwiftUI course: www.hackingwit...
    Watch the full Swift for Complete Beginners playlist here: • Swift for Complete Beg...
  • НаукаНаука

Комментарии • 12

  • @ulugbeknematjonov566
    @ulugbeknematjonov566 3 года назад +7

    I heve never seen such a easy understanding, thank a ton.

  • @BadMemoryAccess
    @BadMemoryAccess 2 месяца назад

    Now it would be interesting to see how to combine this error handling with NSExceptions. For example if a project has a legacy Objective-C codebase, upon which new features are implemented in Swift.

  • @ostanjaffcompany173
    @ostanjaffcompany173 2 года назад +1

    You are a genius. Thanks a lot.

  • @АдамБреннан
    @АдамБреннан 2 года назад +2

    Hi Paul
    Is there a way that I can throw an error that has a custom string? So that I don’t need an enum setup, it just reads the error message from the API
    Thanks

  • @jaredsalzano
    @jaredsalzano 2 года назад +2

    How common is it to use Errors in cases like this, where user enters bad password? In my experience most people just use try/catch when they need to make network requests,. Things like short passwords would just be another case in the same switch block as the happy path. Maybe nobody takes full advantage of the try/catch pattern because we don't like to think about errors :)

  • @NavDhillon
    @NavDhillon Год назад

    Hi Paul,
    I got an error while using \(error.localizedDescription), in the latest version of Xcode.
    please help...

  • @breadone_
    @breadone_ 3 года назад

    how would you make your own localised descriptions?

  • @KK-pq6lu
    @KK-pq6lu 3 года назад +2

    try?

  • @jonathanhirschbaum6754
    @jonathanhirschbaum6754 Год назад

    where throwing error

  • @f00kwhiteblackracismwarsh07
    @f00kwhiteblackracismwarsh07 Год назад +1

    have you covered the do and catch in previous videos?

  • @randygloden
    @randygloden 2 года назад

    When I saw you use !, it made me think this had something to do with how I have to handle optionals like:
    let offset = currentKeyNotes.firstIndex(of: keyOf)!
    This works, but I'm told this is "dangerous"
    So, after watching this, thought I would trying to handle it this way:
    do {try offset = currentKeyNotes.firstIndex(of: keyOf) }
    catch{
    print("Evidently keyOf doesn't exist in currentKeyNotes")
    }
    hmmm, that gives an error, trying to figure out how to do handle this correctly