Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm throw catch swift 2.0

Tags:

realm

swift2

does anyone know the syntax for the try-catch of the following realm function is?

realm.write() {
  realm.add(whatever)
}

I'm getting the following error:

call can throw but it is not marked with 'try' and the error is not handled

like image 537
Michael Avatar asked Nov 30 '22 00:11

Michael


1 Answers

From what I imagine realm.write() can throw an exception. In Swift 2 you handle exceptions with do/catch and try.

I suspect that you should do something like this:

do {
   try realm.write() {
      realm.add(whatever)
   }
} catch {
    print("Something went wrong!")
}

If realm.write() throws an exception, print statement will be invoked immediately.

like image 78
tgebarowski Avatar answered Dec 10 '22 11:12

tgebarowski