Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What errors does FileManager throw?

What are all the errors that can be thrown by FileManager's methods? Specifically, I'm interested in the errors throwable by attributesOfItem(atPath:).

This is how I want to use it:

do {
    let inode = try FileManager.default.attributesOfItem(atPath: somePath)[.systemFileNumber]
} catch SomeError.someSpecificError (let someContext) {
    /* implementation omitted... */
}
like image 789
Wowbagger and his liquid lunch Avatar asked Oct 16 '25 03:10

Wowbagger and his liquid lunch


1 Answers

It can be like the following (see more file related constants in documentation for CocoaError)

do {
    let inode = try FileManager.default.attributesOfItem(atPath: somePath)[.systemFileNumber]
} catch CocoaError.fileNoSuchFile {
    print("Error: no such file exists")
} catch CocoaError.fileReadNoPermission {
    print("Error: you don't have permissions")
} catch {
    // something unknown
}
like image 112
Asperi Avatar answered Oct 18 '25 16:10

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!