Skip to content

Exceptions are swallowed at non-event handler callsites when ExceptionHandler is null #582

@udlose

Description

@udlose

There are classes that take an Action<Exception> exceptionHandler as a param to the ctor. A value of null is acceptable and valid.

Example:

protected GenericLineTransformer(Action<Exception> exceptionHandler)
{
    _exceptionHandler = exceptionHandler;
}

Here is an example of a non-event handler callsite:

GenericLineTransformer:ColorizeLine

protected override void ColorizeLine(DocumentLine line)
{
    try
    {
        TransformLine(line, CurrentContext);
    }
    catch (Exception ex)
    {
        _exceptionHandler?.Invoke(ex);
    }
}

If _exceptionHandler is null, exceptions caught here are swallowed. This isn't intuitive. I would assume that if I don't supply an _exceptionHandler, all exceptions would not be handled (or swallowed). @danipen has confirmed that the current behavior is not correct.

Important

The one exception to the rule is event handlers - by design, per Microsoft, event handlers should never throw exceptions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions