TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
0
326.3k
Exception
Jun 25 2013 11:16 AM
There is a statement in a book saying that "Every Exception object contains a ToString() method and a Message field". Message field is obvious this is highlighted in the following program. Please explain what is meant by ToString() method.
using System;
public class TryBankAccount
{
public static void Main()
{
BankAccount acct = new BankAccount();
try
{
acct.SetAccountNum(1234);
acct.SetBalance(-1000);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
Console.ReadKey();
}
}
public class BankAccount
{
private int accountNum;
private double balance;
public int GetAccountNum()
{
return accountNum;
}
public void SetAccountNum(int acctNumber)
{
accountNum = acctNumber;
}
public double GetBalance()
{
return balance;
}
public void SetBalance(double bal)
{
if (bal < 0)
{
NegativeBalanceException nbe = new NegativeBalanceException();
throw (nbe);
}
balance = bal;
}
}
public class NegativeBalanceException : ApplicationException
{
private static string msg = "Bank balance is negative.";
public NegativeBalanceException() : base(msg)
{
}
}
Reply
Answers (
3
)
Array Sequence Validation
Regex help