The dispose pattern is primarily used in languages whose runtime environment have automatic garbage collection (see motivation below).
Other resources can be managed in exactly the same way: being acquired in a constructor or factory, and released by an explicit close or dispose method.
This approach is known as the Resource Acquisition Is Initialization (RAII) idiom, and is used in languages with deterministic memory management (e.g. C++).
If the intervening code raises an exception, the function exits early and the file is never closed, so the resource is leaked.
One disadvantage of this approach is that it requires the programmer to explicitly add cleanup code in a finally block.
To make the safe use of the dispose pattern less verbose, several languages have some kind of built-in support for resources held and released in the same block of code.
The C# language features the using statement[2] that automatically calls the Dispose method on an object that implements the IDisposable interface: which is equal to: Similarly, the Python language has a with statement that can be used to similar effect with a context manager object.
The context manager protocol requires implementing __enter__ and __exit__ methods which get automatically called by the with statement construct, to prevent duplication of code that would otherwise occur with the try/finally pattern.
[4] It can be used on objects that implement the AutoCloseable interface (that defines method close()): Beyond the key problem of correct resource management in the presence of returns and exceptions, and heap-based resource management (disposing objects in a different scope from where they are created), there are many further complexities associated with the dispose pattern.
This means that all methods on the object that use the resource potentially fail, concretely usually by returning an error or raising an exception.
Disposal in the presence of inheritance and composition of objects that hold resources have analogous problems to destruction/finalization (via destructors or finalizers).