How to "globally" catch exceptions that occur in instances of objects

I am currently writing a winforms application (C #).

I use the Enterprise Library Exception Handler, following a fairly standard approach to what I see. IE: In the main Program.cs method, I connected an event handler to the Application.ThreadException event, etc.

This approach works well and handles exceptional application circumstances.

In one of my business objects, I throw various exceptions in the Set accessor of one of the object properties

set {

   if (value > MaximumTrim)
    throw new CustomExceptions.InvalidTrimValue("The value of the minimum trim...");

   if (!availableSubMasterWidthSatisfiesAllPatterns(value))
        throw new CustomExceptions.InvalidTrimValue("Another message...");

   _minimumTrim = value;
}

( " " ) , - - , . , , ( , ..), , , , - , : , -. , , .

, , Application.ThreadException, , .

Application.ThreadException, "... , ". - ? .

, : explicity , Application.ThreadException. , Enterprise Library. , , catch, , "" .

try
{
    if (value > MaximumTrim)
        throw new CustomExceptions.InvalidTrimValue("The value of the minimum...");

    if (!availableSubMasterWidthSatisfiesAllPatterns(value))
        throw new CustomExceptions.InvalidTrimValue("Another message");

    _minimumTrim = value;
}
catch (Exception ex)
{
    Program.ThreadExceptionHandler.ProcessUnhandledException(ex);
}

AppDomain.UnhandledException, .

, - , . , , try catch, , ?

+3
3

, ( - Main):

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

- , ...

0

MSDN, Application.ThreadException , . , catch - , ?

- AppDomain.UnhandledException. , Application.ThreadException, , AppDomain.

0

Application.ThreadException AppDomain.CurrentDomain.UnhandledException !

, .

0

Source: https://habr.com/ru/post/1704052/


All Articles