尝试抛出错误,但为什么呢?

Try throwing an error, but why?

我正在尝试从文档目录中检索图像以填充集合视图,但我的 try 块 returns 和 error 但我不知道是什么错误是什么或为什么会发生。

func refreshCollectionView() {
    let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
    let url = NSURL(fileURLWithPath: path)

    let filePath = url.appendingPathComponent(imagesDirectoryPath)?.path
    let fileManager = FileManager.default    

    if fileManager.fileExists(atPath: filePath!) {
        print("FILE AVAILABLE")
        do {
            titles = try FileManager.default.contentsOfDirectory(atPath: imagesDirectoryPath)
            print(titles.count)
            for image in titles {
                let data = FileManager.default.contents(atPath: imagesDirectoryPath + "/\(image)")
                let image = UIImage(data: data!)
                myImages.append(image!)
            }
            self.collectionView?.reloadData()
        } 
        catch {
            print("Error")    
        }
    }
    else {        
        print("FILE NOT AVAILABLE")    
    }    
}

print(titles.count) 行从未被执行并且错误被捕获但是错误是什么?

if fileManager.fileExists(atPath: filePath!) {
    print("FILE AVAILABLE")
    do {
        // ...
    } catch {
        print("Error:", error)
    }
}

这将显示实际错误