Cannot call public method [newbie]
-
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
-
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
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.
-
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.
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
-
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
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.