Click here to Skip to main content
15,895,667 members
Home / Discussions / C#
   

C#

 
QuestionMoved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
#realJSOP19-Nov-10 1:40
mve#realJSOP19-Nov-10 1:40 
AnswerRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
Luc Pattyn19-Nov-10 1:50
sitebuilderLuc Pattyn19-Nov-10 1:50 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 13:51
dpminusa20-Nov-10 13:51 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 14:54
dpminusa20-Nov-10 14:54 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
Luc Pattyn20-Nov-10 16:02
sitebuilderLuc Pattyn20-Nov-10 16:02 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 20:06
dpminusa20-Nov-10 20:06 
AnswerRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
Pete O'Hanlon19-Nov-10 2:34
mvePete O'Hanlon19-Nov-10 2:34 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 14:14
dpminusa20-Nov-10 14:14 
using System;
using System.Security.Permissions;

public class Test {

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

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

      throw new Exception("2");

      // Output:
      //   Catch clause caught : 1
      //   MyHandler caught : 2
   }

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

   public static void Main() {
      Example();
   }
}


This works.

If the user recreates the exception (they do pound on the keys and mouse) it does not seem to catch the second throw. Not sure there is a way to deal with that. This helps as part of the solution.

Thanks.
"Coding for fun and profit ... mostly fun"

AnswerRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
_Erik_19-Nov-10 3:46
_Erik_19-Nov-10 3:46 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 14:18
dpminusa20-Nov-10 14:18 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
_Erik_20-Nov-10 16:01
_Erik_20-Nov-10 16:01 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 20:01
dpminusa20-Nov-10 20:01 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
_Erik_20-Nov-10 23:21
_Erik_20-Nov-10 23:21 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa21-Nov-10 4:46
dpminusa21-Nov-10 4:46 
AnswerRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
Rhys Gravell21-Nov-10 23:57
professionalRhys Gravell21-Nov-10 23:57 
Questiondatetimepicker with multiple selected dates Pin
ajithnamboodiri18-Nov-10 19:58
ajithnamboodiri18-Nov-10 19:58 
AnswerRe: datetimepicker with multiple selected dates Pin
Mycroft Holmes18-Nov-10 20:46
professionalMycroft Holmes18-Nov-10 20:46 
AnswerRe: datetimepicker with multiple selected dates Pin
RobCroll19-Nov-10 0:55
RobCroll19-Nov-10 0:55 
AnswerRe: datetimepicker with multiple selected dates Pin
Gregory Gadow19-Nov-10 9:40
Gregory Gadow19-Nov-10 9:40 
AnswerRe: datetimepicker with multiple selected dates Pin
thatraja20-Nov-10 2:13
professionalthatraja20-Nov-10 2:13 
QuestionPrint a data using GDI object in windows form Pin
ragupathi.p18-Nov-10 17:55
ragupathi.p18-Nov-10 17:55 
AnswerRe: Print a data using GDI object in windows form Pin
Luc Pattyn18-Nov-10 18:26
sitebuilderLuc Pattyn18-Nov-10 18:26 
GeneralRe: Print a data using GDI object in windows form Pin
ragupathi.p22-Nov-10 19:24
ragupathi.p22-Nov-10 19:24 
QuestionVersioning Question Pin
Richard Andrew x6418-Nov-10 13:51
professionalRichard Andrew x6418-Nov-10 13:51 
AnswerRe: Versioning Question PinPopular
Luc Pattyn18-Nov-10 14:14
sitebuilderLuc Pattyn18-Nov-10 14:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.