赞
踩
*localizedrecoveryoptions;本地恢复建议
@property (nullable, readonly, strong) id recoveryattempter;
@property (nullable, readonly, copy) nsstring *helpanchor;
预定义的userinfo键名
nsstring *const nsunderlyingerrorkey;//推荐的标准方式,通用键
nsstring *const nslocalizeddescriptionkey; //
详细描述键
nsstring *const nslocalizedfailurereasonerrorkey; // 失败原因键
nsstring *const nslocalizedrecoverysuggestionerrorkey; //恢复建议键
nsstring *const nslocalizedrecoveryoptionserrorkey; // 恢复选项键
//其他键
nsstring *const nsrecoveryattemptererrorkey;
nsstring *const nshelpanchorerrorkey;
nsstring *const nsstringencodingerrorkey ;
nsstring *const nsurlerrorkey;
nsstring *const nsfilepatherrorkey;
用法示例:
nsdictionary *userinfo1 = [nsdictionary dictionarywithobjectsandkeys:@"由于文件不存在,无法打开", nslocalizeddescriptionkey, @"失败原因:文件不存在", nslocalizedfailurereasonerrorkey, @"恢复建议:请创建该文件",nslocalizedrecoverysuggestionerrorkey,nil];
nserror *error = [[nserror alloc] initwithdomain:nscocoaerrordomain code:4 userinfo:userinfo1];//此处code是4,对照下面对照表4代表文件不存在。userinfo传userinfo1 查看自定义打印。userinfo传nil,查看本地化描述。
nslog(@"========%@",[error localizeddescription]);
nslog(@"========%@",[error localizedfailurereason]);
nslog(@"========%@",[error localizedrecoverysuggestion]);
二、nserror错误code对照表
foundation constants reference
nserror codes
nserror c
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。