BLL层抛异常

之前合作开发的时候我就说过UI层与BLL层的区别,但是通过上一次刘兵师兄对我们的指点,我对其又有了一些新的认识。

UI层,即与界面做交互的,而BLL层是处理业务逻辑的。

UI层的任务:将界面层的数据打包发送给BLL层,然后将BLL层的信息呈现到界面上。

BLL层的任务:使用界面层的数据对业务进行逻辑处理,然后将结果或异常反馈给UI层。

下面我主要来为大家演示一下登录的BLL抛异常以及UI层捕获异常的使用:

登录的BLL层:

<!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --> ''' <summary> ''' 查看登录信息是否存在 ''' </summary> ''' <param name="entityUserInfo">用户信息</param> ''' <returns>登录是否成功</returns> ''' <remarks>2011-3-20 15:22 by dan</remarks> Public Function RecordCheck(ByVal entityUserInfo As UserInfo) As Boolean Dim checkResult As Boolean Dim iuser As IUser iuser = DataAccess.UserCreate() Try If Not IsNothing(iuser.Check(entityUserInfo)) Then checkResult = True Else checkResult = False Throw New Exception End If Return checkResult Catch ex As Exception Throw New Exception("登录信息填写错误!") End Try End Function

登录的UI层:

''' <summary> ''' 单击确定按钮 ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks>2011-4-30 16:11 by dan</remarks> Private Sub Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ok.Click ' "判断文本框是否为空" …… '填充参数记录 Dim entityUserInfo As New UserInfo entityUserInfo.Fill(Trim(txtUserName.Text), Trim(txtPwd.Text), Trim(cboUserLevel.Text)) Try If bllUserInfo.RecordCheck(entityUserInfo) Then Me.Hide() …… frmMain.Show() '判断用户级别 If entityUserInfo.userLevel = "管理员" Then frmAdmin.Show() ElseIf entityUserInfo.userLevel = "操作员" Then frmOperator.Show() ElseIf entityUserInfo.userLevel = "一般用户" Then frmGeneral.Show() End If End If Catch ex As Exception MsgBox(ex.Message, vbOKOnly + vbInformation, "提示") Clear() txtUserName.Focus() End Try End Sub

 注意:如果将bllUserInfo.RecordCheck(entityUserInfo)写到了Try……Catch……End Try语句之外,
则会出现“Exception was unhandled”错误。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值