In C++, there are several types of smart pointers that can be used with exception 
handling. One of the most common is the std::unique_ptr, which is a part of the
C++ Standard Template Library (STL).

A simple example of using std::unique_ptr with exception handling is as follows:

Copy code
#include <memory>
#include <iostream>

int main()
{
    try
    {
        std::unique_ptr<int> myInt(new int(5));
        std::cout << "Value of myInt: " << *myInt << std::endl;
    }
    catch (const std::bad_alloc& e)
    {
        std::cerr << "Memory allocation failed: " << e.what() << std::endl;
    }
    return 0;
}

In this example, std::unique_ptr is used to dynamically allocate an int object
with the value of 5. If the memory allocation fails, the std::bad_alloc exception
is caught and an error message is displayed. Since std::unique_ptr takes ownership
of the memory it points to, it will automatically release the memory when it goes
out of scope, so there is no need to manually delete the pointer.

The std::unique_ptr can be useful in situations where it is important to ensure
that dynamically allocated memory is properly managed and that any errors are
handled in a consistent and predictable way.

Additionally, std::shared_ptr is another exception-safe smart pointer in C++,
which allows multiple pointers to point to the same dynamically allocated memory,
and the memory will be deallocated only when all shared_ptr pointing to it goes 
out of scope.

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: