• Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • C# newbie

    Discussion in 'General Discussion Forum' started by nexriz, Jun 7, 2010.

    1. nexriz

      nexriz New Member

      Joined:
      Jan 15, 2010
      Messages:
      11
      Likes Received:
      1
      Trophy Points:
      0
      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: Jun 7, 2010
    2. Anegus

      Anegus New Member

      Joined:
      Jan 15, 2010
      Messages:
      379
      Likes Received:
      2
      Trophy Points:
      0
      I have no idea what you're asking for...
       
    3. Schoasche

      Schoasche New Member

      Joined:
      May 9, 2010
      Messages:
      2
      Likes Received:
      0
      Trophy Points:
      0
      Hi Guy!

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

      greetings
       
    4. zapman

      zapman Member

      Joined:
      Jan 15, 2010
      Messages:
      95
      Likes Received:
      18
      Trophy Points:
      8
      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: Jun 7, 2010

    Share This Page