i'm writing some exception handling for some C++ MFC code.
I'm facing an issue where my outer exception "UserNotExists" is being caught but the inner exception raises an "Exception Unhandled" error. Can anyone help me to understand why the second exception "WrongPasswordException" isn't being captured by the try catch block?
Context: The function calls the API class with login details from the GUI. The API will check the database to see if the user exists and if the password is correct and throw exceptions accordingly.
Edit: I should add that g_UserAuthenticationApi is a global variable of a DLL export.
//#CMFC.cpp
void CMFCDlg::OnBnClickedOk()
try
{
g_UserAuthenticationAPI->TryLogin(std::wstring(m_Initials), std::wstring(m_Password));
OnOK();
}
catch (std::exception& e)
{
//oops
AfxMessageBox(CString(e.what()));
}
//# UserAthenticationAPI.cpp
bool UserAuthenticationAPI::TryLogin(std::wstring szInitials, std::wstring szPassword)
{
if (!m_AuthRepo->DoesUserExist(szInitials))
throw UserNotExistsException("User initials not found");
auto sb64 = m_HashingRepo->Hash(szPassword);
if (!m_AuthRepo->LoginR(szInitials, sb64))
throw WrongPasswordException("Incorrect Password.");
m_fLoggedIn = true;
m_szInitials = szInitials;
return true;
}
//#UserAuthenticationEceptions.h
// These are all the same...
class UserExistsException: public std::runtime_error
{
public:
UserExistsException(const std::string& msg) : std::runtime_error(msg) {}
};