Question custom base exception and derived exceptions

jnewby72

New member
Joined
Feb 24, 2012
Messages
2
Programming Experience
1-3
The jist of what I am wanting to do is create one simple base custom exception and multiple custom exceptions derived from the base exception. When I create a base custom exception with three constructors, derived custom exceptions can not access all the constructors. The only available constructor in DerivedException is the New() constructor. Why aren't all the constructors available?

VB.NET:
[COLOR=#0000ff]Public[/COLOR] MustInherit [COLOR=#0000ff]Class[/COLOR] BaseException
    [COLOR=#0000ff]Inherits[/COLOR] System.Exception
    
    [COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Sub[/COLOR] [COLOR=#8515ea]New[/COLOR]()
        [COLOR=#0000ff]MyBase[/COLOR].[COLOR=#8515ea]New[/COLOR]()
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub[/COLOR]
    
    [COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Sub[/COLOR] [COLOR=#8515ea]New[/COLOR]([COLOR=#0000ff]ByVal[/COLOR] msg [COLOR=#0000ff]As[/COLOR] [COLOR=#6f002f]String[/COLOR])
        [COLOR=#0000ff]MyBase[/COLOR].[COLOR=#8515ea]New[/COLOR](msg)
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub[/COLOR]
    
    [COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Sub[/COLOR] [COLOR=#8515ea]New[/COLOR]([COLOR=#0000ff]ByVal[/COLOR] msg [COLOR=#0000ff]As[/COLOR] [COLOR=#6f002f]String[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] inner [COLOR=#0000ff]As[/COLOR] Exception)
        [COLOR=#0000ff]MyBase[/COLOR].[COLOR=#8515ea]New[/COLOR](msg, inner)        
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub
End Class
[/COLOR]

VB.NET:
[COLOR=#0000FF]Public[/COLOR] [COLOR=#0000FF]Class[/COLOR] DerivedException
    [COLOR=#0000FF]Inherits[/COLOR] BaseException
[COLOR=#0000FF]End Class
[/COLOR]
 
Constructors are not inherited, which is probably what you mean. Base constructors are of course available for derived class to call from its own constructors.
 
Thanks, JohnH and now I understand. You're correct in that I wanted the constructors to also be inherited. I can stop fighting that uphill battle now. :D
 
Back
Top