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 7634175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:06:10+00:00 2026-05-31T07:06:10+00:00

I have a form program I wrote in Visual Studio 2010. In the program

  • 0

I have a form program I wrote in Visual Studio 2010. In the program I wrote new exceptions file called LibraryGeneralExceptions.cs

namespace Database
{
    public class LibraryGeneralExceptions : Exception
    {
        public LibraryGeneralExceptions()
        {
        }

        public void ItemInsertError()
        {
            MessageBox.Show("Item Insert Error", "Error");
        }

        ...
    }
}

under the same namespace I have

public void ItemInsert(string name,string creator,string publishing,string itemType,string genere, string year)
{
    ...
    if (errorMsg.Length != 0)
    {
       throw new ItemInsertError();
        MessageBox.Show(errorMsg, "error");
    }

under another namespace that uses Database and calls for functions from Database i’m trying to set up a try-catch to catch exceptions that database will make using LibraryGeneralExceptions, but I cannot seem to make it work for some reason.

  • 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-05-31T07:06:11+00:00Added an answer on May 31, 2026 at 7:06 am

    lakovl it seems you may be misunderstanding how exceptions work in C#. One point of reference you may like to start reading is the MSDN article on exceptions and exception handling, please also review the child sections.

    When an exception is thrown it is a point at where a fault occurred, when caught it is being handled, and when re-thrown via a wrapped exception it is a reference that you tried to resolve a fault and couldn’t or were simply catching to log.

    To be analogous imagine you have a chain of people, an ice-cream truck has arrived and one person asks someone to go and buy them an ice-cream, they run off to the truck only to find that the original person didn’t give them enough money. The ice-cream vendor throws an exception InsufficientFundsException which is caught and re-thrown by the colleague. Now, if the collegue is generous enough they may wish to add finding for them, though if they also don’t have funds they will re-throw the exception by wrapping it up. Finally they run back to the originator (this is called bubbling up) which they may then resolve or abandon.

    Now lets examine what you’ve done with your exception. What you’ve tried to do is create an exception type LibraryGeneralExceptions which is fine (except for the plural form, drop the s) though you have created a method ItemInsertError which in your code are treating it as if it is an exception of its own. So let’s try fix your problem.

    Firstly it looks as though you intended to use LibraryGeneralExceptions as a sub-namespace and ItemInsertError is meant to be an exception, so here is a correct implementation:

    namespace Database {
        public class ItemInsertError : Exception {
            public ItemInsertError() : base() {}
            public void ItemInsertError(string message) : base(message) {}
        }
    }
    

    Now let’s examine your insert method, the first thing wrong is you’re handling the exception and alerting the user at the same time, instead, let’s just handle the exception.

    public void ItemInsert(string name,
                           string creator,
                           string publishing,
                           string itemType,
                           string genre,
                           string year) {
        // ...
        if (errorMsg.Length != 0) {
           throw new ItemInsertError(errorMsg);
        }
    }
    

    So now when we invoke the ItemInsert method we will then handle exceptions in that piece of code.

    try {
        ItemInsert("name", "creator", "publishing", "itemType", "genre", 2012);
    } catch (ItemInsertError ex) {
        MessageBox.Show(
            ex.Message, "Error during insert",
            MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    

    From this your user will now have feedback of what went wrong, your client code can now try to recover as in where my prior example decides if we can find more funds or not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a form based program in C# that uses MS access database to
I have created a non-form c# program that uses the NotifyIcon class. The text
I'm working on a C# program, and right now I have one Form and
I have to run some other application from my program and hide it's form.
Let's say I have a multithreaded C++ program that handles requests in the form
i have form action file in another directory but some file send to this
I have the following code: public partial class Form1 : Form { public BindingList<Class>
I have a C# .NET 3.5 Windows Form program with this method: private void
[Visual Studio 2008] I created a new project for console application and modified it
I have a method which save settings to file. This method is called if

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.