当前位置: 首页 > news >正文

自定义异常类的使用...

自定义异常类的使用

-首先定义三个基本类: UErrorMessage.vb , UErrorMessageCollection.vb , UException.vb

-一个Form: Form_UException.vb

UErrorMessage.vb

Namespace Exceptions

Public Class UErrorMessage

Private istg_error_code As String

Private istg_error_cdesc As String

Private istg_error_edesc As String

Public Sub New(ByVal astg_error_code As String, ByVal astg_error_cdesc As String, ByVal astg_error_edesc As String)

SetErrorCode(astg_error_code)

SetErrorDescription(New System.Globalization.CultureInfo("zh-CN"), astg_error_cdesc)

SetErrorDescription(New System.Globalization.CultureInfo("en-US"), astg_error_edesc)

End Sub

Private Sub SetErrorCode(ByVal astg_error_code As String)

istg_error_code = astg_error_code

End Sub

Private Sub SetErrorDescription(ByRef acul_culture_info As System.Globalization.CultureInfo, ByVal astg_error_desc As String)

If acul_culture_info.Name = "zh-CN" Then

istg_error_cdesc = astg_error_desc

ElseIf acul_culture_info.Name = "en-US" Then

istg_error_edesc = astg_error_desc

End If

End Sub

Public Sub FillErrorDescription(ByVal astg_replaced_string As String, ByVal astg_replaced_by_string As String)

istg_error_cdesc.Replace(astg_replaced_string, astg_replaced_by_string)

istg_error_edesc.Replace(astg_replaced_string, astg_replaced_by_string)

End Sub

Public Function GetErrorCode() As String

GetErrorCode = istg_error_code

End Function

Public Overloads Function GetErrorDescription(ByRef acul_culture_info As System.Globalization.CultureInfo) As String

Dim lstg_error_description As String

If acul_culture_info.Name = "zh-CN" Or acul_culture_info.Name = "zh-CHT" Then

lstg_error_description = istg_error_cdesc

ElseIf acul_culture_info.Name = "en-US" Then

lstg_error_description = istg_error_edesc

End If

GetErrorDescription = lstg_error_description

End Function

End Class

End Namespace

UErrorMessageCollection.vb

Namespace Exceptions

Public Class UErrorMessageCollection

Inherits System.Collections.CollectionBase

Public Sub Add(ByVal apmr_parameter As UErrorMessage)

List.Add(apmr_parameter)

End Sub

Public Sub Remove(ByVal aint_index As Integer)

If aint_index > (Count - 1) Or aint_index < 0 Then

' If no widget exists, a messagebox is shown and the operation is

' cancelled.

' System.Windows.Forms.MessageBox.Show("Index not valid!")

Else

List.RemoveAt(aint_index)

End If

End Sub

Public ReadOnly Property Item(ByVal aint_index As Integer) As UErrorMessage

Get

Return CType(List.Item(aint_index), UErrorMessage)

End Get

End Property

Public Function GetItemIndex(ByVal astg_error_code As String) As Integer

Dim lint_index As Integer

Dim lboo_continue As Boolean

lboo_continue = True

lint_index = 0

Do While lboo_continue = True

If CType(List.Item(lint_index), UErrorMessage).GetErrorCode() = astg_error_code Then

lboo_continue = False

Else

lint_index = lint_index + 1

If lint_index > (Count - 1) Then

lboo_continue = False

lint_index = -1

End If

End If

Loop

GetItemIndex = lint_index

End Function

End Class

End Namespace

UException.vb

Namespace Exceptions

Public MustInherit Class UException

Inherits System.Exception

Protected ierm_error_msg_list As UErrorMessageCollection

Protected istg_error_code As String

Protected iexp_current_inner_exception As Exception

Private istg_custom_msg_1 As String

Private istg_custom_msg_2 As String

Private istg_custom_msg_3 As String

Private istg_custom_msg_4 As String

Private istg_custom_msg_5 As String

Private istg_custom_msg_6 As String

Public MustOverride Sub Initialize()

Public Sub New(ByVal astg_error_code As String)

MyBase.New(astg_error_code)

istg_custom_msg_1 = ""

istg_custom_msg_2 = ""

istg_custom_msg_3 = ""

istg_custom_msg_4 = ""

istg_custom_msg_5 = ""

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal astg_error_custom_msg_1 As String)

MyBase.New(astg_error_code)

istg_custom_msg_1 = astg_error_custom_msg_1

istg_custom_msg_2 = ""

istg_custom_msg_3 = ""

istg_custom_msg_4 = ""

istg_custom_msg_5 = ""

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal astg_error_custom_msg_1 As String, ByVal astg_error_custom_msg_2 As String)

MyBase.New(astg_error_code)

istg_custom_msg_1 = astg_error_custom_msg_1

istg_custom_msg_2 = astg_error_custom_msg_2

istg_custom_msg_3 = ""

istg_custom_msg_4 = ""

istg_custom_msg_5 = ""

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal astg_error_custom_msg_1 As String, ByVal astg_error_custom_msg_2 As String, ByVal astg_error_custom_msg_3 As String)

MyBase.New(astg_error_code)

istg_custom_msg_1 = astg_error_custom_msg_1

istg_custom_msg_2 = astg_error_custom_msg_2

istg_custom_msg_3 = astg_error_custom_msg_3

istg_custom_msg_4 = ""

istg_custom_msg_5 = ""

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal astg_error_custom_msg_1 As String, ByVal astg_error_custom_msg_2 As String, ByVal astg_error_custom_msg_3 As String, ByVal astg_error_custom_msg_4 As String)

MyBase.New(astg_error_code)

istg_custom_msg_1 = astg_error_custom_msg_1

istg_custom_msg_2 = astg_error_custom_msg_2

istg_custom_msg_3 = astg_error_custom_msg_3

istg_custom_msg_4 = astg_error_custom_msg_4

istg_custom_msg_5 = ""

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal astg_error_custom_msg_1 As String, ByVal astg_error_custom_msg_2 As String, ByVal astg_error_custom_msg_3 As String, ByVal astg_error_custom_msg_4 As String, ByVal astg_error_custom_msg_5 As String)

MyBase.New(astg_error_code)

istg_custom_msg_1 = astg_error_custom_msg_1

istg_custom_msg_2 = astg_error_custom_msg_2

istg_custom_msg_3 = astg_error_custom_msg_3

istg_custom_msg_4 = astg_error_custom_msg_4

istg_custom_msg_5 = astg_error_custom_msg_5

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal astg_error_custom_msg_1 As String, ByVal astg_error_custom_msg_2 As String, ByVal astg_error_custom_msg_3 As String, ByVal astg_error_custom_msg_4 As String, ByVal astg_error_custom_msg_5 As String, ByVal astg_error_custom_msg_6 As String)

MyBase.New(astg_error_code)

istg_custom_msg_1 = astg_error_custom_msg_1

istg_custom_msg_2 = astg_error_custom_msg_2

istg_custom_msg_3 = astg_error_custom_msg_3

istg_custom_msg_4 = astg_error_custom_msg_4

istg_custom_msg_5 = astg_error_custom_msg_5

istg_custom_msg_6 = astg_error_custom_msg_6

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal aexp_inner_exception As System.Exception)

MyBase.New(astg_error_code, aexp_inner_exception)

istg_custom_msg_1 = ""

istg_custom_msg_2 = ""

istg_custom_msg_3 = ""

istg_custom_msg_4 = ""

istg_custom_msg_5 = ""

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal astg_custom_msg_1 As String, ByVal aexp_inner_exception As System.Exception)

MyBase.New(astg_error_code, aexp_inner_exception)

istg_custom_msg_1 = astg_custom_msg_1

istg_custom_msg_2 = ""

istg_custom_msg_3 = ""

istg_custom_msg_4 = ""

istg_custom_msg_5 = ""

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal astg_custom_msg_1 As String, ByVal astg_custom_msg_2 As String, ByVal aexp_inner_exception As System.Exception)

MyBase.New(astg_error_code, aexp_inner_exception)

istg_custom_msg_1 = astg_custom_msg_1

istg_custom_msg_2 = astg_custom_msg_2

istg_custom_msg_3 = ""

istg_custom_msg_4 = ""

istg_custom_msg_5 = ""

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal astg_custom_msg_1 As String, ByVal astg_custom_msg_2 As String, ByVal astg_custom_msg_3 As String, ByVal aexp_inner_exception As System.Exception)

MyBase.New(astg_error_code, aexp_inner_exception)

istg_custom_msg_1 = astg_custom_msg_1

istg_custom_msg_2 = astg_custom_msg_2

istg_custom_msg_3 = astg_custom_msg_3

istg_custom_msg_4 = ""

istg_custom_msg_5 = ""

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal astg_custom_msg_1 As String, ByVal astg_custom_msg_2 As String, ByVal astg_custom_msg_3 As String, ByVal astg_custom_msg_4 As String, ByVal aexp_inner_exception As System.Exception)

MyBase.New(astg_error_code, aexp_inner_exception)

istg_custom_msg_1 = astg_custom_msg_1

istg_custom_msg_2 = astg_custom_msg_2

istg_custom_msg_3 = astg_custom_msg_3

istg_custom_msg_4 = astg_custom_msg_4

istg_custom_msg_5 = ""

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public Sub New(ByVal astg_error_code As String, ByVal astg_custom_msg_1 As String, ByVal astg_custom_msg_2 As String, ByVal astg_custom_msg_3 As String, ByVal astg_custom_msg_4 As String, ByVal astg_custom_msg_5 As String, ByVal aexp_inner_exception As System.Exception)

MyBase.New(astg_error_code, aexp_inner_exception)

istg_custom_msg_1 = astg_custom_msg_1

istg_custom_msg_2 = astg_custom_msg_2

istg_custom_msg_3 = astg_custom_msg_3

istg_custom_msg_4 = astg_custom_msg_4

istg_custom_msg_5 = astg_custom_msg_5

istg_custom_msg_6 = ""

SetErrorCode(astg_error_code)

Initialize()

End Sub

Public

相关文章:

  • 使用欧几里得定理求最大公约数和最小公倍数
  • 移动设备管理(MDM)与OMA(OTA)DM协议向导(二)——WAP协议(2)
  • 斐波那契数列算法的快速版本
  • 3月OpenParty春晴活动纪实——“如何成为一个高效的程序员”
  • 使用stein 算法计算 最大公约数和最小公倍数
  • 算法练习--多项式加法
  • 高性价比才是王道 三大流行趋势机巅峰对垒
  • mvc 中Range中max和min值晚绑定
  • 网上购物,哪家平台更贴心?——三大网购平台大比拼
  • mvc中使用remote属性来做ajax验证
  • 跨过硬盘瓶颈 体验极速运算——在内存里装系统
  • javascript 获取选中text
  • Windows 7中写字板也能浏览*.docx文档
  • 使用栈结构完成四则运算
  • 是妥协?是阴谋?Office 14为何大打“兼容”牌
  • 2019年如何成为全栈工程师?
  • crontab执行失败的多种原因
  • Druid 在有赞的实践
  • javascript数组去重/查找/插入/删除
  • k8s 面向应用开发者的基础命令
  • Vue全家桶实现一个Web App
  • 浮动相关
  • 技术:超级实用的电脑小技巧
  • 前嗅ForeSpider中数据浏览界面介绍
  • 使用 QuickBI 搭建酷炫可视化分析
  • 小程序开发之路(一)
  • Redis4.x新特性 -- 萌萌的MEMORY DOCTOR
  • 通过调用文摘列表API获取文摘
  • (TipsTricks)用客户端模板精简JavaScript代码
  • (附源码)springboot宠物医疗服务网站 毕业设计688413
  • (附源码)ssm学生管理系统 毕业设计 141543
  • (七)Knockout 创建自定义绑定
  • (学习日记)2024.03.12:UCOSIII第十四节:时基列表
  • (一)VirtualBox安装增强功能
  • (原创)Stanford Machine Learning (by Andrew NG) --- (week 9) Anomaly DetectionRecommender Systems...
  • (原創) 如何優化ThinkPad X61開機速度? (NB) (ThinkPad) (X61) (OS) (Windows)
  • (转)重识new
  • (转载)hibernate缓存
  • ***检测工具之RKHunter AIDE
  • . ./ bash dash source 这五种执行shell脚本方式 区别
  • .net 无限分类
  • .NET/C# 避免调试器不小心提前计算本应延迟计算的值
  • .NET处理HTTP请求
  • .Net多线程总结
  • .NET开发人员必知的八个网站
  • .skip() 和 .only() 的使用
  • @JsonFormat与@DateTimeFormat注解的使用
  • [].shift.call( arguments ) 和 [].slice.call( arguments )
  • [AIGC] Java 和 Kotlin 的区别
  • [asp.net core]project.json(2)
  • [C/C++]_[初级]_[关于编译时出现有符号-无符号不匹配的警告-sizeof使用注意事项]
  • [C++] sqlite3_get_table 的使用
  • [CC2642r1] ble5 stacks 蓝牙协议栈 介绍和理解
  • [CentOs7]搭建ftp服务器(2)——添加用户
  • [DAX] MAX函数 | MAXX函数