I have a Foo class as follows
Foo.h
#pragma once
class Foo
{
public:
Foo() = default;
~Foo() = default;
void DoSomething();
};
Foo.cpp
#include "Foo.h"
void Foo::DoSomething()
{
throw "something happened";
}
And I use the class like:
#include <iostream>
#include "Foo.h"
int main()
{
try
{
Foo foo;
foo.DoSomething();
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
}
}
I expect the code to go in the catch block. However, it never goes in there. What am I doing wrong here?