Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1012769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:59:45+00:00 2026-05-16T09:59:45+00:00

I have a basic solution file (.sln) where I was able to reproduce a

  • 0

I have a basic solution file (.sln) where I was able to reproduce a problem I have been facing recently.

It contains 3 projects:
1.) MathTest.lib – containing methods that might cause a mathematical error, like acos(1.1).
2.) MathTestDll.dll – calls the methods from the above lib.
3.) UnitTest.exe – calls the exported method in the DLL that should cause the error.

What I’m trying to do is fairly simple:
The following code contains the _matherr() routine and should ideally link fine. The call to acos() with a value of 1.1 is invalid (invalid input) and should cause an error which should be handled by the implemented _matherr() handler. I hope I’m right about the behavior of _matherr(). Please let me know.
MathTest.lib

#include "MathTest.h"
#include <iostream>
#include <math.h>

int _matherr(_exception* _Except)
{
    std::cout << _Except->name;
    return -1;
}

void MathTest::ThrowMatherr(float par)
{
    float result = acos(par);
    std::cout << result;
}

This ‘ThrowMatherr()’ method will be called by the DLL as follows:
MathTestDll.dll

void MatherrCaller::CauseMatherr()
{
    MathTest* mathtest = new MathTest();
    mathtest->ThrowMatherr(1.1);
}

which is then exported as:

extern "C" __declspec(dllexport) void CallThisToCauseMatherr();

void CallThisToCauseMatherr()
{
    MatherrCaller* caller = new MatherrCaller();
    caller->CauseMatherr();
}

This exported method will be called by a simple test.
UnitTest.exe

#include <windows.h>

typedef void (*METHODTOCALL)(); 

int main()
{
    HMODULE module = LoadLibrary((LPCSTR)"..\\Debug\\MatherrTestDll.dll");
    if(module != NULL)
    { 
        METHODTOCALL ProcAdd = (METHODTOCALL) GetProcAddress(module, (LPCSTR)"CallThisToCauseMatherr"); 
        if (NULL != ProcAdd)
        {
            (ProcAdd)();
        }

        FreeLibrary(module); 
    }

    return 0;
}

All methods get called fine. But the acos() method which has been passed invalid input never calls the _matherr() error handler. Please let me know how I can fix this.

I had to make the question detailed to get my point through. Please don’t mind.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:59:46+00:00Added an answer on May 16, 2026 at 9:59 am

    It is explicitly mentioned in the documentation for _matherr:

    For special error handling, you can
    provide a different definition of
    _matherr. If you use the dynamically linked version of the C run-time
    library (Msvcr90.dll), you can replace
    the default _matherr routine in a
    client executable with a user-defined
    version. However, you cannot
    replace
    the default _matherr routine
    in a DLL client of Msvcr90.dll.

    You’ll need to put the override in the EXE module. Alter your unit test to accommodate this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic C# console application that reads a text file (CSV format)
Currently, i have basic C++ and PHP skills. But, i want to switch to
I have a basic form with controls that are databound to an object implementing
I have a basic understanding of mock and fake objects, but I'm not sure
I have a basic CRUD form that uses PageMethods to update the user details,
I have a basic model in which i have specified some of the fields
I have a basic ActiveRecord model in which i have two fields that i
I have a basic cs-major understanding of multi-threading but have never had to do
I have a basic quiz/survey type application I'm working on, and I'd like to
I have a basic ajax application, which will not work, instead the php code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.