diff --git a/ExceptionHandling/ExceptionHandling.sln b/ExceptionHandling/ExceptionHandling.sln new file mode 100644 index 0000000..1e0acf8 --- /dev/null +++ b/ExceptionHandling/ExceptionHandling.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.271 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExceptionHandling", "ExceptionHandling\ExceptionHandling.csproj", "{830E9E45-F036-4DB4-8492-6EED4EADEFA5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {830E9E45-F036-4DB4-8492-6EED4EADEFA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {830E9E45-F036-4DB4-8492-6EED4EADEFA5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {830E9E45-F036-4DB4-8492-6EED4EADEFA5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {830E9E45-F036-4DB4-8492-6EED4EADEFA5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {841BBAE6-75CB-46F1-B364-657DA3BB140F} + EndGlobalSection +EndGlobal diff --git a/ExceptionHandling/ExceptionHandling/App.config b/ExceptionHandling/ExceptionHandling/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/ExceptionHandling/ExceptionHandling/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ExceptionHandling/ExceptionHandling/ExceptionHandling.csproj b/ExceptionHandling/ExceptionHandling/ExceptionHandling.csproj new file mode 100644 index 0000000..ab4c60d --- /dev/null +++ b/ExceptionHandling/ExceptionHandling/ExceptionHandling.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {830E9E45-F036-4DB4-8492-6EED4EADEFA5} + Exe + ExceptionHandling + ExceptionHandling + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ExceptionHandling/ExceptionHandling/Program.cs b/ExceptionHandling/ExceptionHandling/Program.cs new file mode 100644 index 0000000..79e1a71 --- /dev/null +++ b/ExceptionHandling/ExceptionHandling/Program.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ExceptionHandling +{ + class Program + { + static void Main(string[] args) + { + Division(); + + Console.ReadKey(); + } + + static void Division() + { + try + { + Console.BackgroundColor = ConsoleColor.Black; + + Console.WriteLine("Division. Type the first number:"); + string numberOne = Console.ReadLine(); + + Console.WriteLine("Type the second number:"); + string numberTwo = Console.ReadLine(); + + Console.WriteLine($"Result: {Convert.ToInt32(numberOne) / Convert.ToInt32(numberTwo)}"); + } + catch (DivideByZeroException ex) + { + Console.WriteLine("Du kænn itte dele på null ama:\n" + ex.GetType()); + } + catch (FormatException ex) + { + Console.WriteLine("Du må skrive inn tal ama\n:" + ex.StackTrace); + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + finally + { + Division(); + } + } + } +} diff --git a/ExceptionHandling/ExceptionHandling/Properties/AssemblyInfo.cs b/ExceptionHandling/ExceptionHandling/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..509da9e --- /dev/null +++ b/ExceptionHandling/ExceptionHandling/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ExceptionHandling")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ExceptionHandling")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("830e9e45-f036-4db4-8492-6eed4eadefa5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]