自定义异常类的使用
-首先定义三个基本类: 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 color: b
分享到:
相关推荐
Java自定义异常类_1.txtJava自定义异常类_1.txt
Java自定义异常类_2.txtJava自定义异常类_2.txtJava自定义异常类_2.txt
Java SE程序 自定义异常类Java SE程序 自定义异常类Java SE程序 自定义异常类Java SE程序 自定义异常类Java SE程序 自定义异常类Java SE程序 自定义异常类Java SE程序 自定义异常类Java SE程序 自定义异常类Java SE...
解决dubbo接口自定义异常的捕捉问题,dubbo消费者可以捕捉到提供者所抛出的自定义异常。
java基本语法,自定义异常类
创建自定义异常类后,就可以触发和使用该异常: try: raise MyError(2*2) except MyError as e: print('My exception occurred, value:', e.value) 自定义异常 运行结果: 当然,在不对自定义异常进行捕获处理时,...
实现一个自定义异常类IntegerException
异常处理,异常类 //创建MyException异常类 //指明要抛出的异常 //如果当前字母英文字母以外的字符 等等等等
java 自定义异常实例二 java 自定义异常实例二
java 自定义异常实例一 java 自定义异常实例一
Java自定义异常处理详细介绍,包括了很多比较经典的案例,可以自己研究自定义异常
python烟花代码-24-自定义异常代码实现之异常类.ev4.rar
在Spring AOP中,切面通过常规类(基本模式方法)或者通过使用了注解@Aspect的常规类来实现。 连接点(Joint point):是指在程序执行期间的一个点,比如某个方法的执行或者是某个异常的处理。在Spring AOP中,一个...
自定义异常Exception,对于产品开发等比较有用
Python 异常机制 09_自定义异常类_raise抛出异常.mp4
博主看到新服务是封装的自定义异常,准备入手剖析一下,...第一步:肯定是在Springboot启动的过程中进行的异常处理初始化,于是就找到了handlerExceptionResolver类,在创建该类的时候,会进行添加我们自定义异常。
Java异常处理--自定义异常类及课后练习
在实际项目中一般自定义异常的方法,通常把一个业务逻辑抽象成一个常量类
异常(Exception)一般分为两大类SystemException、ApplicationException,前者是预定义的异常类,后者是用户自定义异常类时需要继承的类 简单自定义异常类Demo using System; using ...
步骤详细,调理明确,是初学者的宝典。谢谢啦。