Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Cannot call public method [newbie]

Cannot call public method [newbie]

Scheduled Pinned Locked Moved C#
csharpvisual-studiolinqcomtools
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jon 80
    wrote on last edited by
    #1

    I am coding this utility to test raising of an exception, however, I have noted that Visual Studio 2010 IDE does not allow me to call the ArithmeticUtilityException.Divide() method. Why? I have also (desperately) tried to declare the class as static and the Divide() method as static, however, no joy either.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace CustomException
    {
    class Program
    {
    static void Main(string[] args)
    {
    ArithmeticUtilityException utility = new ArithmeticUtilityException();
    ///Decimal myNumber = ArithmeticUtilityException.???
    }
    }

    public class ArithmeticUtilityException : ApplicationException
    { 
        public ArithmeticUtilityException() : base() {}
        public ArithmeticUtilityException(string message) : base(message) {}
        public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
    }
    
    public static class ArithmethicUtility
    {
        public decimal Divide(decimal number, decimal divisor)
        {
            try
            { return number / divisor; }
            catch (Exception err)
            {
                /\*  
                 \* Create an instance of the specialized exception class, and, 
                 \* place the original error in the InnerException property. 
                 \*/
                ArithmeticUtilityException errNew = new ArithmeticUtilityException("Divide by zero", err);
                throw errNew;
            }
        }
    }
    

    }

    :confused: NOTES 1. Related link Static Classes and Static Class Members (C# Programming Guide)
    2. Personal note. ..\Training\CustomException.

    Jon

    OriginalGriffO 1 Reply Last reply
    0
    • J jon 80

      I am coding this utility to test raising of an exception, however, I have noted that Visual Studio 2010 IDE does not allow me to call the ArithmeticUtilityException.Divide() method. Why? I have also (desperately) tried to declare the class as static and the Divide() method as static, however, no joy either.

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;

      namespace CustomException
      {
      class Program
      {
      static void Main(string[] args)
      {
      ArithmeticUtilityException utility = new ArithmeticUtilityException();
      ///Decimal myNumber = ArithmeticUtilityException.???
      }
      }

      public class ArithmeticUtilityException : ApplicationException
      { 
          public ArithmeticUtilityException() : base() {}
          public ArithmeticUtilityException(string message) : base(message) {}
          public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
      }
      
      public static class ArithmethicUtility
      {
          public decimal Divide(decimal number, decimal divisor)
          {
              try
              { return number / divisor; }
              catch (Exception err)
              {
                  /\*  
                   \* Create an instance of the specialized exception class, and, 
                   \* place the original error in the InnerException property. 
                   \*/
                  ArithmeticUtilityException errNew = new ArithmeticUtilityException("Divide by zero", err);
                  throw errNew;
              }
          }
      }
      

      }

      :confused: NOTES 1. Related link Static Classes and Static Class Members (C# Programming Guide)
      2. Personal note. ..\Training\CustomException.

      Jon

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      jon_80 wrote:

      does not allow me to call the ArithmeticUtilityException.Divide() method. Why?

      Because you don't have one?

      public class ArithmeticUtilityException : ApplicationException
      { 
          public ArithmeticUtilityException() : base() {}
          public ArithmeticUtilityException(string message) : base(message) {}
          public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
      }
      
      public static class ArithmethicUtility
      {
          public decimal Divide(decimal number, decimal divisor)
          {
          ...
          }
      }
      

      Divide is a member of ArithmethicUtility, not ArithmeticUtilityException

      Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      J 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        jon_80 wrote:

        does not allow me to call the ArithmeticUtilityException.Divide() method. Why?

        Because you don't have one?

        public class ArithmeticUtilityException : ApplicationException
        { 
            public ArithmeticUtilityException() : base() {}
            public ArithmeticUtilityException(string message) : base(message) {}
            public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
        }
        
        public static class ArithmethicUtility
        {
            public decimal Divide(decimal number, decimal divisor)
            {
            ...
            }
        }
        

        Divide is a member of ArithmethicUtility, not ArithmeticUtilityException

        Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

        J Offline
        J Offline
        jon 80
        wrote on last edited by
        #3

        Thanks

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using CustomException;

        namespace CustomException
        {
        class Program
        {
        static void Main(string[] args)
        {
        ArithmethicUtility utility = new ArithmethicUtility();
        Decimal myNumber = utility.Divide(5, 0);
        }
        }

        public class ArithmeticUtilityException : ApplicationException
        { 
            public ArithmeticUtilityException() : base() {}
            public ArithmeticUtilityException(string message) : base(message) {}
            public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
        }
        
        public class ArithmethicUtility
        {
            public decimal Divide(decimal number, decimal divisor)
            {
                try
                { return number / divisor; }
                catch (Exception err)
                {
                    /\*  
                     \* Create an instance of the specialized exception class, and, 
                     \* place the original error in the InnerException property. 
                     \*/
                    ArithmeticUtilityException errNew = new ArithmeticUtilityException("Divide by zero", err);
                    throw errNew;
                }
            }
        }
        

        }

        Jon

        OriginalGriffO 1 Reply Last reply
        0
        • J jon 80

          Thanks

          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;
          using CustomException;

          namespace CustomException
          {
          class Program
          {
          static void Main(string[] args)
          {
          ArithmethicUtility utility = new ArithmethicUtility();
          Decimal myNumber = utility.Divide(5, 0);
          }
          }

          public class ArithmeticUtilityException : ApplicationException
          { 
              public ArithmeticUtilityException() : base() {}
              public ArithmeticUtilityException(string message) : base(message) {}
              public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
          }
          
          public class ArithmethicUtility
          {
              public decimal Divide(decimal number, decimal divisor)
              {
                  try
                  { return number / divisor; }
                  catch (Exception err)
                  {
                      /\*  
                       \* Create an instance of the specialized exception class, and, 
                       \* place the original error in the InnerException property. 
                       \*/
                      ArithmeticUtilityException errNew = new ArithmeticUtilityException("Divide by zero", err);
                      throw errNew;
                  }
              }
          }
          

          }

          Jon

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          You're welcome. :-D

          Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups