From 7b3e8c17c27987f31766256830d13e6bb3921595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Wed, 9 Jan 2019 22:54:31 +0100 Subject: [PATCH] Started Exceptionhandling --- Exceptionhandling/App.config | 6 +++ Exceptionhandling/Calculator.cs | 10 ++++ Exceptionhandling/Exceptionhandling.csproj | 54 ++++++++++++++++++++ Exceptionhandling/Program.cs | 36 +++++++++++++ Exceptionhandling/Properties/AssemblyInfo.cs | 36 +++++++++++++ TrainingAdvancedTechniques.sln | 6 +++ 6 files changed, 148 insertions(+) create mode 100644 Exceptionhandling/App.config create mode 100644 Exceptionhandling/Calculator.cs create mode 100644 Exceptionhandling/Exceptionhandling.csproj create mode 100644 Exceptionhandling/Program.cs create mode 100644 Exceptionhandling/Properties/AssemblyInfo.cs diff --git a/Exceptionhandling/App.config b/Exceptionhandling/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/Exceptionhandling/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Exceptionhandling/Calculator.cs b/Exceptionhandling/Calculator.cs new file mode 100644 index 0000000..ced22ac --- /dev/null +++ b/Exceptionhandling/Calculator.cs @@ -0,0 +1,10 @@ +namespace Exceptionhandling +{ + public class Calculator + { + public int Divide(int numerator, int denomenator) + { + return numerator / denomenator; + } + } +} diff --git a/Exceptionhandling/Exceptionhandling.csproj b/Exceptionhandling/Exceptionhandling.csproj new file mode 100644 index 0000000..82a7fec --- /dev/null +++ b/Exceptionhandling/Exceptionhandling.csproj @@ -0,0 +1,54 @@ + + + + + Debug + AnyCPU + {56A6C16C-D8D7-4581-8ABA-9A2478868628} + 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/Program.cs b/Exceptionhandling/Program.cs new file mode 100644 index 0000000..8128b38 --- /dev/null +++ b/Exceptionhandling/Program.cs @@ -0,0 +1,36 @@ +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) + { + try + { + var calculator = new Calculator(); + var result = calculator.Divide(5, 0); + + } + catch (DivideByZeroException dx) + { + Console.WriteLine("You cannot divide by 0."); + } + catch (ArithmeticException ax) + { + Console.WriteLine(""); + } + catch (Exception ex) + { + Console.WriteLine("Sorry, an unexpected error occured. :" + ex.Message); + } + finally + { + } + } + } +} diff --git a/Exceptionhandling/Properties/AssemblyInfo.cs b/Exceptionhandling/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a24ddad --- /dev/null +++ b/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("56a6c16c-d8d7-4581-8aba-9a2478868628")] + +// 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")] diff --git a/TrainingAdvancedTechniques.sln b/TrainingAdvancedTechniques.sln index 389c8a0..3366729 100644 --- a/TrainingAdvancedTechniques.sln +++ b/TrainingAdvancedTechniques.sln @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nullable_types", "Nullable_ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dynamics", "Dynamics\Dynamics.csproj", "{C504A101-B4E7-4228-BF69-13816521A909}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exceptionhandling", "Exceptionhandling\Exceptionhandling.csproj", "{56A6C16C-D8D7-4581-8ABA-9A2478868628}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {C504A101-B4E7-4228-BF69-13816521A909}.Debug|Any CPU.Build.0 = Debug|Any CPU {C504A101-B4E7-4228-BF69-13816521A909}.Release|Any CPU.ActiveCfg = Release|Any CPU {C504A101-B4E7-4228-BF69-13816521A909}.Release|Any CPU.Build.0 = Release|Any CPU + {56A6C16C-D8D7-4581-8ABA-9A2478868628}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {56A6C16C-D8D7-4581-8ABA-9A2478868628}.Debug|Any CPU.Build.0 = Debug|Any CPU + {56A6C16C-D8D7-4581-8ABA-9A2478868628}.Release|Any CPU.ActiveCfg = Release|Any CPU + {56A6C16C-D8D7-4581-8ABA-9A2478868628}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE