Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
[Oo]bj/

# mstest test results
TestResults

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates
*.sln.ide

# Build results
[Dd]ebug/
[Rr]elease/
x64/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.log
*.vspscc
*.vssscc
.builds

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*

# Intellij Rider
.idea

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Xamarin.Android Resource.Designer.cs files (Auto-Generated)
**/*.Android.*/**/[Rr]esource.[Dd]esigner.cs

# Click-Once directory
publish

# Publish Web Output
*.Publish.xml

# NuGet Packages Directory
packages

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
[Bb]in
[Oo]bj
sql
TestResults
[Tt]est[Rr]esult*
*.Cache
ClientBin
[Ss]tyle[Cc]op.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
Thumbs.db

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML

*.userprefs
Components

.DS_Store
.stversions
.stfolder

*.orig
*.bak
.nuget/packages.config
/UpgradeLog.htm
/.vs
*.patch

*.sublime-*
9 changes: 9 additions & 0 deletions AwaitException.Project/ExceptionThrower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@ public async Task DelayAndThrow(int sleepForMilliseconds)

throw new AwaitException();
}

public async void VoidDelayAndThrow(int sleepForMilliseconds)
{
await Task.Delay(sleepForMilliseconds);

awaitCompleted = true;

throw new AwaitException();
}
}
}
Binary file not shown.
26 changes: 25 additions & 1 deletion AwaitExpception.Test/Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using NUnit.Framework;
using Project;

Expand Down Expand Up @@ -34,5 +35,28 @@ public async Task TestFreeFallExceptionThrow()
// make sure we have waited long enough
Assert.True(thrower.AwaitCompleted);
}

// This test fails the process with exception, not yet found a way to run it normally as a test.
// Comment that out if need to run other tests
[Test]
public void TestExceptionThrowInAsyncVoid()
{
var thrower = new ExceptionThrower();
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) =>
{
// Unfortunately I haven't yet found the way to not fail here.
// Looks like the exception is caught but the process fails despite of that fact
Console.WriteLine("The exception is actually caught globally");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add this code after we know how to deal with it correctly? Right now it is just dead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is the key code here. But it doesn't work as expected for some reason. This is a generic mechanism for catching uncaught exceptions. So we know we expect an uncaught exception, but this method doesn't handle the exception it catches. The exception just propagates further for some reason. The console log here is important that in the console you will see a log that the exception was actually caught with this mechanism before it crashes the app.

Copy link
Author

@SergeyNesteruk SergeyNesteruk Apr 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, looks like UnhandledException is not intended to recover from the exception it just notifies that your application will fail in a moment so you for example can log something. And we are logging that. Seems like there is nothing we can do to prevent the crash. Looks like that is an example of a 100% crash if exception is raised.


// Make sure thrower finished async operation
Assert.True(thrower.AwaitCompleted, "Exception handled globally");
};

// We try to assure exception is thrown here
Assert.Throws<AwaitException>(() => thrower.VoidDelayAndThrow(5));

// Make sure the thrower worked correctly
Assert.True(thrower.AwaitCompleted, "Exception handled locally");
}
}
}
Binary file not shown.