asp.net – 返回异常值
发布时间:2020-12-16 07:33:35 所属栏目:asp.Net 来源:网络整理
导读:为什么这段代码不能编译? 它给了我错误: not all code paths return a value 码: public bool isUserProfileHashed(string username){ bool isHashed = false; MembershipUser u = null; u = Membership.GetUser(username); if (u != null) { try { u.Get
为什么这段代码不能编译?
它给了我错误:
码: public bool isUserProfileHashed(string username) { bool isHashed = false; MembershipUser u = null; u = Membership.GetUser(username); if (u != null) { try { u.GetPassword(); } catch (Exception exception) { // An exception is thrown when the GetPassword method is called for a user with a hashed password isHashed = true; return isHashed; } return isHashed; } 解决方法
你忘了在if之外放一个返回,把它放在if结束的括号之后
public bool isUserProfileHashed(string username) { bool isHashed = false; MembershipUser u = null; u = Membership.GetUser(username); if (u != null) { try { u.GetPassword(); } catch { // An exception is thrown when the GetPassword method is called for a user with a hashed password isHashed = true; } } return isHashed; } [编辑]删除不必要的回报(@FredrikM?rk)未使用的捕获异常因此也将其删除. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- .net – 不能使用moles来模拟MVC框架
- asp.net – 我无法解决unhandeld异常:在已设置H
- asp.net-mvc-3 – MVC默认重定向错误页面并不总是
- asp.net-mvc – 如果value为空,在razor模板上放置
- 可以按需生成ASP.NET黄色死亡屏幕(YSOD)吗?
- ASP.Net MVC C#另一个viewmodel中的两个viewmode
- asp.net – IIS URL重写模块url为小写
- ASP.NET Web Forms jQuery
- asp.net-mvc – ASP.NET MVC标识:多个登录路径并
- asp.net-mvc-3 – 在IIS上运行时,ASP.NET Web应用
热点阅读