Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p> I would change the whole approach to exceptions and errors:</p> <ul> <li>Create a new assembly (project) and reference it in your application</li> <li>Declare new shared events which accept your personal datatype (referenced assembly)</li> <li>Declare at least one shared function (referenced assembly) which does a RaiseEvent on your new events</li> <li>Add handlers (main application) for your shared events in which you react accordingly</li> <li>Call your function from within the main application, passing your own parameters whenever you need to throw errors / exceptions</li> </ul> <p>This way you circumvent many programming mistakes <strong>and</strong> centralize error and exception-handling.</p> <pre class="lang-vb prettyprint-override"><code>Public Module IDENTIFIERS Public Enum EvtMsg ERR_MYERR ERR_MYERR2 End Enum Public Enum EvtClass EXCEPTION ERR End Enum End Module Public Class Events Shared Event Err(ByVal code As EvtMsg) Shared Event Exception(ByRef iEx As Exception) Public Shared Sub Raise(ByVal iEvtClass As EvtClass, ByVal iMsg As EvtMsg, Optional ByRef iEx As Exception = Nothing) If Not [Enum].IsDefined(GetType(EvtClass), iEvtClass) Then Dim ex As New ArgumentOutOfRangeException("unbekannte Event-Klasse '" &amp; iEvtClass.ToString &amp; "' übergeben", "iEvtClass") RaiseEvent Exception(ex) End If If Not [Enum].IsDefined(GetType(EvtMsg), iMsg) Then Dim ex As New ArgumentOutOfRangeException("unbekannte Event-Msg '" &amp; iMsg.ToString &amp; "' übergeben", "iMsg") RaiseEvent Exception(ex) End If Select Case iEvtClass Case EvtClass.ERR RaiseEvent Err(iMsg) Case EvtClass.EXCEPTION If iEx IsNot Nothing Then RaiseEvent Exception(iEx) Else Dim ex As New MissingFieldException("Raise() ohne Exception aufgerufen, iMsg : " &amp; iMsg &amp; "EvtClass : " &amp; iEvtClass.ToString(), "iEx") RaiseEvent Exception(ex) End If End Select End Sub End Class </code></pre> <p>And now you can easily use these error-handlers in any assembly which references your error-assembly:</p> <h2>Constructor</h2> <pre class="lang-vb prettyprint-override"><code>AddHandler Events.Err, AddressOf Err AddHandler Events.Exception, AddressOf Except </code></pre> <h2>Class-body</h2> <pre class="lang-vb prettyprint-override"><code>Private Sub Except(ByRef iEx As Exception) 'do your stuff here End Sub Private Sub Err(ByVal Err As EvtMsg) 'do your stuff here End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload