Xcode-beta (7A120f): Add type specificity to throws
| Originator: | owensd | ||
| Number: | rdar://21301710 | Date Originated: | 09-Jun-2015 09:28 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-beta (7A120f) |
| Classification: | Enhancement | Reproducible: | Always |
It’s annoying that we cannot add type information for the type of errors we want to throw. This leads to needing to mark functions as throws or needing to have a catch-all at the end.
Adding “throws MyCustomError” as a constraint would improve the code snippet below.
func base() throws MyCustomError {
throw MyCustomError.Dance
}
- code snippet -
enum MyCustomError: ErrorType {
case Happy
case Dance
}
func base() throws {
throw MyCustomError.Dance
}
func handle() {
do {
try base()
print("valid value")
}
catch MyCustomError.Happy {
print("Happy error")
}
catch MyCustomError.Dance {
print("Dance error")
}
catch { /* this is really not required */
print("catch all, because no types")
}
}
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!