rspec/rules/S1048/vbnet/rule.adoc
Fred Tingaud 51369b610e
Make sure that includes are always surrounded by empty lines (#2270)
When an include is not surrounded by empty lines, its content is inlined
on the same line as the adjacent content. That can lead to broken tags
and other display issues.
This PR fixes all such includes and introduces a validation step that
forbids introducing the same problem again.
2023-06-22 10:38:01 +02:00

62 lines
1.8 KiB
Plaintext

== Why is this an issue?
The Finalize method is used to perform cleanup operations on unmanaged resources held by the current object before the object is destroyed. The method is protected and therefore is accessible only through this class or through a derived class. When you override `Finalize`, you should never throw an exception in it, as you are risking having your application terminated without a graceful cleanup.
If `Finalize` or an override of `Finalize` throws an exception and the runtime is not hosted by an application that overrides the default policy and the behavior of the `UnhandledExceptionEventHandler`, then
the runtime terminates the process immediately without graceful cleanup (`finally` blocks and `Finalizer` methods are not executed).
The rule reports on throw statements used in finalizers.
=== Noncompliant code example
[source,vbnet,diff-id=1,diff-type=noncompliant]
----
Class MyClass
Protected Overrides Sub Finalize()
Throw New NotImplementedException() ' Noncompliant
End Sub
End Class
----
=== Compliant solution
[source,vbnet,diff-id=1,diff-type=compliant]
----
Class MyClass
Protected Overrides Sub Finalize()
End Sub
End Class
----
== Resources
=== Documentation
* https://learn.microsoft.com/en-us/dotnet/api/system.object.finalize[Object.Finalize method]
* https://learn.microsoft.com/en-us/dotnet/api/system.appdomain[App Domain]
* https://learn.microsoft.com/en-us/dotnet/api/system.appdomain.unhandledexception[AppDomain.UnhandledException Event]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this 'throw' statement.
=== Highlighting
The 'throw' statement.
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]