To find out the possible exceptions you have to read the documentation of what you will use. Any other attempt will not solve.
There are functions and methods that document your exceptions in the signature itself which can facilitate since the compiler will inform you that you forget to treat the exception. But this kind of exception is controversial, abused and often treats the wrong way just because it’s required.
Conscious capture of exceptions is the only appropriate means. This will only occur with the will of the programmer and reading of the documentation.
There’s a documentation on the subject.
The most traditional way is:
do {
try funcao()
//faz algo aqui
} catch TipoErro.ErroEspecifico { //pega exceção específica
//faz algo aqui
} catch TipoErro.ErroEspecifico where x == 0 { //exceção filtrada
//faz algo aqui
} catch { //pega qualquer exceção não especificada anteriormente
//faz algo aqui
}
I put in the Github for future reference.
In Swift exception are not special types, they can be represented by several forms. One of the most common is an enumeration derived from ErrorType
.
There are a number of other ways to capture exceptions but this is the most traditional way. I would need more specific questions.
There are some very interesting forms in the language that it would be useful to have other languages.
Be careful not to overdo catching the exceptions that you can’t do anything useful. I I talk a lot about abuse.
This article has helped me a lot, but I haven’t been able to figure out how to find possible Exceptions when they are undocumented and you don’t have the code: https://www.hackingwithswift.com/new-syntax-swift-2-error-handling-try-catch
– Delfino
You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? Something needs to be improved?
– Maniero