Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8128335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:50:30+00:00 2026-06-06T07:50:30+00:00

i have about 20 possible exception messages that i want thrown when an error

  • 0

i have about 20 possible exception messages that i want thrown when an error occurs.
i need somthng like this when catching the exception

Try
    ' do domthing
Catch ex As CustomInvalidArgumentException
     'do domthing
Catch ex As CustomUnexcpectedException
     'do domthing
Catch ex As Exception
     'do domthing
End Try

currently i have a class like this

<Serializable()> _
Public Class CustomException
    Inherits Exception

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal message As String)
        MyBase.New(message)
    End Sub

    Public Sub New(ByVal format As String, ByVal ParamArray args As Object())
        MyBase.New(String.Format(format, args))
    End Sub

    Public Sub New(ByVal message As String, ByVal innerException As Exception)
        MyBase.New(message, innerException)
    End Sub

    Public Sub New(ByVal format As String, ByVal innerException As Exception, ByVal ParamArray args As Object())
        MyBase.New(String.Format(format, args), innerException)
    End Sub

    Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
        MyBase.New(info, context)
    End Sub
End Class

do i have to create a class that inherits from Exception for each type of exception

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:50:33+00:00Added an answer on June 6, 2026 at 7:50 am

    No you don’t need to make each exception class to directly inherit from Exception. But you need to make sure that all you custom exceptions can be derived from Exception via parent hierarchy. For example, see the following inheritance tree:

    Exception
    |
    |-MyGenericException
    |  |-MyFooException
    |  |-MyBarException
    |
    |-OtherGenericException  
       |-OtherFooException
       |-OtherBarException
    

    See, that some exception classes do not directly inherit from the Exception, however they have a parent class which, in tern, is derived from the Exception.

    A sample code is in C# written in notepad but hopefully you can get the idea.

    2 more general exception classes inherit from Exception. They are MyIOException and MySecurityException. The other four less general classes derive from them.

    //------------ Networking
    public class MyIOException : Exception
    {
        public string AdditionalData {get; set;}
    }
    public class MyNetworkFailureIOException : MyIOException
    {
        public string Reason {get; set;}
    }
    public class MyRemoteFileNotFoundIOException : MyIOException
    {
        public string RemotePath {get; set;}
    }
    
    //------------ Security
    public class MySecurityException : Exception
    {
        public string UserName {get; set;}
    }
    public class MyAccessDeniedException : MySecurityException
    {
        public string PolicyName {get; set;}
    }
    public class MyUnauthorizedException : MySecurityException
    {
        public string CodeName {get; set;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about IPTC metadata. Is it possible to search images that
I have been trying to read as much on stackoverflow about this as possible,
I have read about gstreamer support for rtp and it should be possible to
I have about 10 drop down list controls that get populated. Instead of copying/pasting
We have about 7 app servers running .NET windows services that ping a single
I would like to catch an exception an tell if it was me that
This one puzzles me. I get an error about seek when I'm not even
I have a project where I am required to fix this program that has
This is a follow up to a previous question that I had before about
I am currently having an issue of losing a message. This error occurs rarely,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.