Created
July 24, 2015 19:54
-
-
Save traviskirton/06041590e8af4d939267 to your computer and use it in GitHub Desktop.
Getting used to the do try catch system in Swift2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// test | |
// | |
// Created by travis on 2015-07-24. | |
// Copyright © 2015 C4. All rights reserved. | |
// | |
import Cocoa | |
enum TestError: ErrorType { | |
case trueError | |
} | |
class ViewController: NSViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
do { | |
try willOnlyThrowIfTrue(true) | |
print("worked") | |
} catch TestError.trueError { | |
print("Caught true error") | |
} catch { | |
print("Another Error") | |
} | |
do { | |
try willOnlyThrowIfTrue(false) | |
print("worked") | |
} catch TestError.trueError { | |
print("Caught true error") | |
} catch { | |
print("Another Error") | |
} | |
} | |
func willOnlyThrowIfTrue(value: Bool) throws { | |
if value { throw TestError.trueError } | |
} | |
override var representedObject: AnyObject? { | |
didSet { | |
// Update the view, if already loaded. | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment