tutorial

Page 193

MyBase.New(errorMessage) End Sub

' Constructor that takes message string and inner exception Public Sub New(ByVal errorMessage As String, _ ByVal innerException As Exception) ' Call the base class constructor MyBase.New(errorMessage, innerException) End Sub End Class

The ChannelNotAvailableException class shown above is fairly trivial and you’ll notice that the non-default constructors do nothing more than initializing their corresponding base class counter parts through the base class argument-list initializer. That’s it – we’re done setting up our custom exception class. We’ll see how to put this to use in our TV channel surfer application. Let’s put together some code for the channel surfer class. Code listing in C# class ChannelSurfer { private const int MAX_CHANNELS = 80; private int m_nCurrentChannel; ChannelSurfer() { // Set channel 1 as the default m_nCurrentChannel = 1; } public int CurrentChannel { get { // Return the current channel return m_nCurrentChannel; } } // Rest of the class implementation goes here . . . }

Code listing in VB.NET Public Class ChannelSurfer Private Const MAX_CHANNELS As Integer = 80


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.