What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal
RebornBuddy Forums

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

C# newbie

nexriz

New Member
Joined
Jan 15, 2010
Messages
11
Hi, i was wondering if some1 could help me..

How do i make a try-catch to go off when i type a letter or a character..
 
Last edited:
Hi Guy!

Try/Catch is for Exception Handling.
Search in google, you will find enough.

greetings
 
If you write a letter instead of a number, it'll "jump" to catch and write an Exception.

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int number;

            try
            {
                //What you want to try! 
                Console.Write("Write a number: ");
                number = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex); //Writes Exception
            }

        }
    }
}
Microsoft: http://msdn.microsoft.com/en-us/library/0yd65esw%28VS.80%29.aspx
Csharpfriends: http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=128


 
Last edited:
Back
Top