     /// Throws a `JSONError` if the receiver does not wrap a dictionary or if the given key does
     /// not exist in the dictionary.
     public func sub(key: String) throws -> JSONValue {
+        try throwIfError()
         guard let value = try self.asDictionary()[key] else {
             throw JSONError(.MissingKey(key: key), json: self)
         }

    }
    
    private func asDictionary() throws -> [String:JSONValue] {
        guard let objectDictionary = self.wrapped as? [String:AnyObject] else {
            throw JSONError(.IncompatibleType(typename: "dictionary"), json: self)
        }
        return objectDictionary.transform({ JSONValue($0) })
    }
}


    public init(_ any: Any) {
        wrapped = any
    }
    
    internal init(error: ErrorType) {
        self.wrapped = ()
        self.error = error
    }
}

// Private helpers
extension JSONValue {
    private func asArray() throws -> [JSONValue] {
        try throwIfError()
        guard let objectArray = self.wrapped as? [AnyObject] else {
            throw JSONError(.IncompatibleType(typename: "array"), json: self)
        }
