Answers for "exceptions c#"

C#
4

exceptions c#

// inside try you write the code you want to try and run
try {
	string name = "person";
	Console.WriteLine(name[8]);
}

/* if there are any problems/error the catch will activate what
is written inside it */

catch (Exception error){
	Console.WriteLine(error.Message);
}
/* you can give it the default Exception (catches any error) to catch
or a specific Exception like 'DivideByZeroException' */

finally {
	Console.WriteLine("c# exceptions");
}
/* the finally keyword runs the code inside it
 after the try and catch (even if an exception occurred) */

// wait before closing
Console.ReadKey();
Posted by: Guest on April-26-2022

C# Answers by Framework

Browse Popular Code Answers by Language