You are viewing a single comment's thread. Return to all comments →
import Foundation
/* * Define an ErrorType */ enum StringToIntTypecastingError: Error { case BadString }
func stringToInt(inputString: String) throws -> Int { guard let int = Int(inputString) else { throw StringToIntTypecastingError.BadString } return int }
/* * Read the input */ let inputString = readLine()!
do { try print(stringToInt(inputString: inputString)) } catch StringToIntTypecastingError.BadString { print("Bad String") }
**// I am getting Error reading result file.You should use exception handling concepts.
but output printing correct can any one please help in this in Swift language **
Seems like cookies are disabled on this browser, please enable them to open this website
Day 16: Exceptions - String to Integer
You are viewing a single comment's thread. Return to all comments →
import Foundation
/* * Define an ErrorType */ enum StringToIntTypecastingError: Error { case BadString }
/* * Read the input */ let inputString = readLine()!
do { try print(stringToInt(inputString: inputString)) } catch StringToIntTypecastingError.BadString { print("Bad String") }
**// I am getting Error reading result file.You should use exception handling concepts.
but output printing correct can any one please help in this in Swift language **