# std::basic_filebuf<CharT,Traits>::~basic_filebuf

> C++ Atlas: `cppatlas.com/w/cpp/io/basic_filebuf/~basic_filebuf` | Source: https://en.cppreference.com/w/cpp/io/basic_filebuf/~basic_filebuf | Domain: Input/output

Calls close() to close the associated file and destructs all other members of basic_filebuf. If an exception occurs during the destruction of the object, including the call to close(), it is caught and not rethrown.

## Official Specification Summary (cppreference)

Calls `close()` to close the associated file and destructs all other members of `basic_filebuf`. If an exception occurs during the destruction of the object, including the call to `close()`, it is caught and not rethrown.

### Parameters

(none)

### Return value

(none)

### Notes

Typically called by the destructor of `std::basic_fstream`.

### Example

> Note: This section is incomplete Reason: no example

### Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

| DR | Applied to | Behavior as published | Correct behavior |
| --- | --- | --- | --- |
| LWG 622 | C++98 | it was unclear how to handle the exception thrown during destruction | it is caught but not rethrown |

### See also

- [(constructor)](https://en.cppreference.com/w/cpp/io/basic_filebuf/basic_filebuf): constructs a `basic_filebuf` object (public member function)
- [`close`](https://en.cppreference.com/w/cpp/io/basic_filebuf/close): flushes the put area buffer and closes the associated file (public member function)

---
Attribution: content from https://en.cppreference.com/w/cpp/io/basic_filebuf/~basic_filebuf (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.