Skip to content

Fatal error using try!  #430

Closed
Closed
@Silve2611

Description

@Silve2611

As already mentioned in #339 the try! will cause a program to crash if multiple programs access the database at the same time.
This is not only happening when using Scalar but also when using

SELECT * FROM table

let table = Table("TProperties")
var all = [Row]()
do{
    all = Array(try db.prepare(table))
}catch{
     print("getSettings failed")
}

The reason behind it is the Generator type

extension Statement : GeneratorType {
    public func next() -> [Binding?]? {
        return try! step() ? Array(row) : nil
    }
}

My solution for it is the following change but i couldn't test yet if it is really working

extension Statement : GeneratorType {
    public func next() -> [Binding?]? {
        var result:[Binding?]?
        do{
            result = try step() ? Array(row) : nil
        }catch{
            result = nil
        }
        return result
        //return try! step() ? Array(row) : nil
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions