Skip to content

Commit

Permalink
Changed the exception callback name to be more accurate
Browse files Browse the repository at this point in the history
Changed to use 'callback' instead of 'handler' to help indicate this is not meant to handle exceptions, but instead provide visibility into their details when they occur.
  • Loading branch information
Sam Storie authored and TravisTheTechie committed Aug 19, 2016
1 parent 7f1bd58 commit b22d788
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void AddCommandLineDefinition(string name, Action<string> callback)

public void OnException(Action<Exception> callback)
{
_settings.ExceptionHandler = callback;
_settings.ExceptionCallback = callback;
}

public Host CreateHost()
Expand Down
6 changes: 3 additions & 3 deletions src/Topshelf/Hosts/ConsoleRunHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public TopshelfExitCode Run()
{
// Call the custom exception handler if it is not null
//
_settings.ExceptionHandler?.Invoke(ex);
_settings.ExceptionCallback?.Invoke(ex);

_log.Error("An exception occurred", ex);

Expand Down Expand Up @@ -150,7 +150,7 @@ void CatchUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
// Call the custom exception handler if it is not null
//
_settings.ExceptionHandler?.Invoke((Exception)e.ExceptionObject);
_settings.ExceptionCallback?.Invoke((Exception)e.ExceptionObject);

_log.Fatal("The service threw an unhandled exception", (Exception)e.ExceptionObject);

Expand Down Expand Up @@ -195,7 +195,7 @@ void StopService()
{
// Call the custom exception handler if it is not null
//
_settings.ExceptionHandler?.Invoke(ex);
_settings.ExceptionCallback?.Invoke(ex);

_log.Error("The service did not shut down gracefully", ex);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Topshelf/Hosts/InstallHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ public TimeSpan StopTimeOut
get { return _settings.StopTimeOut; }
}

public Action<Exception> ExceptionHandler
public Action<Exception> ExceptionCallback
{
get { return _settings.ExceptionHandler; }
get { return _settings.ExceptionCallback; }
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Topshelf/Runtime/HostSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public interface HostSettings
TimeSpan StopTimeOut { get; }

/// <summary>
/// A callback to provide additional exception handling beyond what is already provided
/// A callback to provide visibility into exceptions while Topshelf is performing its
/// own handling.
/// </summary>
Action<Exception> ExceptionHandler { get; }
Action<Exception> ExceptionCallback { get; }
}
}
2 changes: 1 addition & 1 deletion src/Topshelf/Runtime/Windows/WindowsHostSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ public string ServiceName

public TimeSpan StopTimeOut { get; set; }

public Action<Exception> ExceptionHandler { get; set; }
public Action<Exception> ExceptionCallback { get; set; }
}
}
16 changes: 8 additions & 8 deletions src/Topshelf/Runtime/Windows/WindowsServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected override void OnStart(string[] args)
{
// Call the custom exception handler if it is not null
//
_settings.ExceptionHandler?.Invoke(ex);
_settings.ExceptionCallback?.Invoke(ex);

_log.Fatal("The service did not start successfully", ex);

Expand All @@ -156,7 +156,7 @@ protected override void OnStop()
{
// Call the custom exception handler if it is not null
//
_settings.ExceptionHandler?.Invoke(ex);
_settings.ExceptionCallback?.Invoke(ex);

_log.Fatal("The service did not shut down gracefully", ex);
ExitCode = (int)TopshelfExitCode.StopServiceFailed;
Expand Down Expand Up @@ -186,7 +186,7 @@ protected override void OnPause()
{
// Call the custom exception handler if it is not null
//
_settings.ExceptionHandler?.Invoke(ex);
_settings.ExceptionCallback?.Invoke(ex);

_log.Fatal("The service did not pause gracefully", ex);
throw;
Expand All @@ -208,7 +208,7 @@ protected override void OnContinue()
{
// Call the custom exception handler if it is not null
//
_settings.ExceptionHandler?.Invoke(ex);
_settings.ExceptionCallback?.Invoke(ex);

_log.Fatal("The service did not resume successfully", ex);
throw;
Expand All @@ -229,7 +229,7 @@ protected override void OnShutdown()
{
// Call the custom exception handler if it is not null
//
_settings.ExceptionHandler?.Invoke(ex);
_settings.ExceptionCallback?.Invoke(ex);

_log.Fatal("The service did not shut down gracefully", ex);
ExitCode = (int)TopshelfExitCode.StopServiceFailed;
Expand All @@ -253,7 +253,7 @@ protected override void OnSessionChange(SessionChangeDescription changeDescripti
{
// Call the custom exception handler if it is not null
//
_settings.ExceptionHandler?.Invoke(ex);
_settings.ExceptionCallback?.Invoke(ex);

_log.Fatal("The service did not shut down gracefully", ex);
ExitCode = (int)TopshelfExitCode.StopServiceFailed;
Expand All @@ -275,7 +275,7 @@ protected override void OnCustomCommand(int command)
{
// Call the custom exception handler if it is not null
//
_settings.ExceptionHandler?.Invoke(ex);
_settings.ExceptionCallback?.Invoke(ex);

_log.Error("Unhandled exception during custom command processing detected", ex);
}
Expand All @@ -298,7 +298,7 @@ void CatchUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
// Call the custom exception handler if it is not null
//
_settings.ExceptionHandler?.Invoke((Exception)e.ExceptionObject);
_settings.ExceptionCallback?.Invoke((Exception)e.ExceptionObject);

_log.Fatal("The service threw an unhandled exception", (Exception)e.ExceptionObject);

Expand Down

0 comments on commit b22d788

Please sign in to comment.