'What error do I need to throw to for a specific catch block to handle + Swift error handling

I want to add code to throw an error that requires the "catch let printerErrorsecond" and the last catch block to handle an error. I have tried updating the value for the toPrinter parameter to a number of values without any luck. I also tried a number of else if statements and cannot seem to get either of the last two catch blocks to handle the errors. It seems like a case for both could be added in the PrinterError enum but after several attempts I could not resolve the issue. Any code based resolutions you can provide the better!

enum PrinterError: Error {
    case outOfPaper
    case noToner
    case onFire
}

func send(job: Int, toPrinter printerName: String) throws -> String {
    if printerName == "Never Has Toner" {
        throw PrinterError.noToner
    } else if printerName == "Fire" {
        throw PrinterError.onFire
    } else if printerName == "Empty" {
        throw PrinterError.outOfPaper
    }
    return "Job sent"
}

do {
    let printerResponse = try send(job: 1440, toPrinter: "Gutenberg")
    print(printerResponse)
} catch PrinterError.onFire {
    print("I'll just put this over here, with the rest of the fire.")
} catch let printerError as PrinterError {
    print("Printer error: \(printerError).")
} catch {
    print(error)
}
// Prints "Job sent"


Solution 1:[1]

try to implement it by this way

enum PrinterError: Error {
    case outOfPaper
    case noToner
    case onFire
    case deFault
    case noHandeling
}

func send(job: Int, toPrinter printerName: String) throws -> String {
    switch printerName {
    case PrinterError.outOfPaper.localizedDescription:
        print("outOfPaper")
        return PrinterError.outOfPaper.localizedDescription
    case PrinterError.noToner.localizedDescription:
        print("noToner")
        return PrinterError.noToner.localizedDescription
    case PrinterError.onFire.localizedDescription:
        print("onFire")
        return PrinterError.onFire.localizedDescription
    default:
        print("default")
        return PrinterError.deFault.localizedDescription
    }
}


    do {
        try send(job: 100, toPrinter: "AAA")
    } catch {
        print(error.localizedDescription)
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Woop