C# - Programming Language
This course covers the basics of programming in C#. Work your way through the videos and we'll teach you everything you need to know to start your programming journey!

Try & Catch

Lesson 24
Author : Mike Dane
Last Updated : November, 2017


Code

Copy// this code takes a number from the user and
// divides 10 by it. Enter '0' to trigger the exception
try{
  int division = 10 / Convert.ToInt32(Console.ReadLine());
}catch(DivideByZeroException e){
     Console.WriteLine(e);
}catch(Exception e){
     Console.WriteLine(e);
     // Not best practice to use general Exception
}

// throws new exception
throw new DivideByZeroException("can't divide numbers");