Run mode does not behave to spec with code throwing an exception in using
See original GitHub issueThis caught me off-guard, assuming that Dispose()
would not get called if an exception occurred, yet all the SO questions about exceptions inside using
s claimed the opposite.
using System;
class P
{
static void Main()
{
try
{
Use();
}
catch (Exception)
{
Console.WriteLine("Caught");
}
}
static void Use()
{
Console.WriteLine("Constructing");
using (new D())
{
Console.WriteLine("Throwing");
throw new Exception();
}
}
class D : IDisposable
{
public void Dispose() => Console.WriteLine("Disposed");
}
}
Expected output (also seen in VS2017):
Constructing
Throwing
Disposed
Caught
Actual output:
Constructing
Throwing
Caught
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Fail with error & stack trace in asynchronous code #529
When an error is thrown from asynchronous code, Jasmine currently has no way of knowing that it happened, skipping subsequent stages (e.g. ...
Read more >Rethrowing Exception without requiring throws Exception?
This code compiles without having to add throws Exception to the method signature. (It behaves similarly with Throwable in place of Exception , ......
Read more >c# - What is the proper way to throwing an exception?
Don't create exceptions that can be thrown in debug mode but not release mode. To identify run-time errors during the development phase, use...
Read more >Creating and Throwing Exceptions
Learn about creating and throwing exceptions. Exceptions are used to indicate that an error has occurred while running a program.
Read more >Exception specifications (throw, noexcept) (C++)
When an exception is thrown from a function declared as throw() in /std:c++14 mode, the result is undefined behavior. No specific function is ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Resolved in default: https://sharplab.io/#v2:C4LgTgrgdgPgAgBgARwIwG4CwAoHcBMSACjgN45KUqoBsKALNQBwAUAlBVedlb0sGACenPkm6jRAVQDOAU3ZYeEgL4i+AYwCGwdQAskLAKIAPdbIAOwAJYB7KByWjxE3mgCcLAEQBhTRADmusCebIouqo5IEbxqaHRwjDLyDrzOou5e3nbSAhDq1lD+IWESiAZQsgDuSAAi7CkSaS7UHp4AKrpgNpVWhcVqLsCd3UgV1SZmlrZQCgNU0fNqsYQ1SCBIAJI1VtLmNtKaAEYANrJqTa4AzAy1O3ty7EgAvAB8LV7bu/uyACb9kRFlEA===
Should be in
master
in a few hours if all goes well.OK so just for curiosity sake (and recording for myself as well) the issue is caused by
Dispose()
hitting the stack limit of Unbreakable, and therefore never executing. The reason why it hits the stack limit is because being infinally
after athrow
seems to add tons of things to the stack:I have an idea for a solution, but not sure if I’ll have time to apply it today.