Jeehut
(Cihat Gündüz)
November 20, 2024, 9:21pm
2
Not exactly what you've suggested – which I personally don't find very readable or intuitive, but that's just my first impression – but I suggested improvements to try-catch myself two times already because I also find the current approach contains too much boilerplate code:
I recently encountered a scenario where I found the existing syntax in Swift unnecessarily complex and less readable:
let data: Data
let response: URLResponse
do {
(data, response) = try await URLSession.shared.data(for: request)
} catch {
throw RequestError.failedToLoadData(error)
}
I believe it would be far more readable and concise if we could write it this way:
do let (data, response) = try await URLSession.shared.data(for: request) catch {
throw RequestError.failedToLoadData(err…
I want to revive a discussion that was started 7 years ago in this thread . I find myself often writing long do blocks when calling into throwing APIs, effectively nesting much more code than actually needed, leading to the catch clause being very far away from the actual code that could have caused its entrance. For example:
func randomMovies(genre: Genre, count: Int) -> [Movie] {
do {
let movies = try Database.loadMovies(byGenre: genre)
// no throwing API calls from here …