X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> C# Handle All Unhandled Exception    
post Jan 8 2017, 02:44 PM

Posts: 1,132
Joined: 19-February 08


i find this code in this link

using System;
using System.Security.Permissions;

public class Example
   [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
   public static void Main()
      AppDomain currentDomain = AppDomain.CurrentDomain;
      currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

      try {
         throw new Exception("1");
      } catch (Exception e) {
         Console.WriteLine("Catch clause caught : {0} \n", e.Message);

      throw new Exception("2");

   static void MyHandler(object sender, UnhandledExceptionEventArgs args)
      Exception e = (Exception) args.ExceptionObject;
      Console.WriteLine("MyHandler caught : " + e.Message);
      Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);

i'm coping this code to C# WPF Project to new class

but application still crash and suddenly exit with out display exception

and this error appear to me
CS0017 C# Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

i solve this error from
project >>> Startup Object
and select first main

why application still suddenly exit or crash

is there some think wrong in copy and paste class

thank you very much for your help
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    20th November 2019 - 03:14 PM