Skip to content

Commit

Permalink
Added version of Exceptions#Handle that will look at the return value…
Browse files Browse the repository at this point in the history
… from the report

Added mkdir statements to post build to make sure folders are present before copying files
  • Loading branch information
theJenix committed Jun 3, 2016
1 parent 3d5e17a commit edc4b25
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
40 changes: 33 additions & 7 deletions NBug/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace NBug
using NBug.Core.Reporting.MiniDump;
using NBug.Core.Util;
using Core.Submission;
using Core.UI;
public static class Exceptions
{
/// <summary>
Expand Down Expand Up @@ -57,12 +58,37 @@ public static void Handle(bool continueExecution, Action body)
});
}

/// <summary>
/// Submits a bug report for the given exception. This function useful for submitting bug reports inside a try-catch block.
/// Note that this function uses the NBug configuration so it will use the pre-configured UI and submission settings.
/// </summary>
/// <param name="exception">The exception to submit as the bug report.</param>
public static void Report(Exception exception)
/// <summary>
/// Similar to <see cref="Filter(Action)"/> but this time, exceptions are not allowed to escape the action body and they are
/// simply swallowed after being queued for reporting, with a small UI displayed to the user (if set so). Note that
/// NBug can halt the execution with <c>Environment.Exit(0);</c> if you configured it to do so with <paramref name="continueExecution"/>
/// parameter set to <see langword="false"/>. You can simply use <c>Handle(true, () => { MyCodeHere(); })</c>
/// </summary>
/// <param name="continueExecution">Decides whether to exit application after handling the exception or continue execution.</param>
/// <param name="body">Body of code to be executed.</param>
public static void Handle(Action body) {
ExecutionFlow ret = ExecutionFlow.BreakExecution;
ExceptionFilters.Filter(
body,
ex =>
{
// Filtering the exception
ret = new BugReport().Report(ex, ExceptionThread.Main);
return true; // Yes proceed to handling the exception
},
ex =>
{
if (ret == ExecutionFlow.BreakExecution) {
Environment.Exit(0);
}
});
}
/// <summary>
/// Submits a bug report for the given exception. This function useful for submitting bug reports inside a try-catch block.
/// Note that this function uses the NBug configuration so it will use the pre-configured UI and submission settings.
/// </summary>
/// <param name="exception">The exception to submit as the bug report.</param>
public static void Report(Exception exception)
{
// Below never exits application by itself (by design) so execution of the application continues normally
new BugReport().Report(exception, ExceptionThread.Main);
Expand All @@ -72,4 +98,4 @@ public static void Dispatch() {
new Dispatcher();
}
}
}
}
12 changes: 11 additions & 1 deletion NBug/NBug.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,21 @@ if $(ConfigurationName)==Release copy "$(TargetPath)" "$(SolutionDir)packages\NB
if $(ConfigurationName)==Release copy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)packages\NBug\tools" /Y</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup>
<PostBuildEvent>if not exist "$(SolutionDir)packages\NBug\lib\net40-client" mkdir "$(SolutionDir)packages\NBug\lib\net40-client"
if not exist "$(SolutionDir)packages\NBug\lib\net40-client" mkdir "$(SolutionDir)packages\NBug\tools"

if $(ConfigurationName)==Release copy "$(TargetPath)" "$(SolutionDir)packages\NBug\lib\net40-client" /Y
if $(ConfigurationName)==Release copy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)packages\NBug\lib\net40-client" /Y
if $(ConfigurationName)==Release copy "$(TargetDir)$(TargetName).xml" "$(SolutionDir)packages\NBug\lib\net40-client" /Y
if $(ConfigurationName)==Release copy "$(TargetPath)" "$(SolutionDir)packages\NBug\tools" /Y
if $(ConfigurationName)==Release copy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)packages\NBug\tools" /Y</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

0 comments on commit edc4b25

Please sign in to comment.