BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

log10: SING Error -> Try/Catch??

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
Dan
Guest





PostPosted: Wed Apr 18, 2007 7:55 pm    Post subject: log10: SING Error -> Try/Catch?? Reply with quote



log10 functions where the value passed to the function is negative
results in a "LOG10: DOMAIN error" if the value is 0 then it's a "LOG10:
SING error" For example the following code will create a DOMAIN error.


#include <math.h>

double DoLogFunction(const double &val)
{
return log10(val);
}

void main()
{
DoLogFunction(0); //SING ERROR
DoLogFunction(-1); //DOMAIN ERROR
}


Try/Catch around the 'DoLogFunction()' function call or even around the
log10 call doesn't work.

Of course I can test val to see if it's negative and non-zero. The
problem is, I think I have done that in the following code:

double DoLogFunction(const double &val)
{
double result = 0;
if (val>0)
{
try
{
result = log10(val);
}
catch (...)
{
;//do nothing, result is already 0
}
}
return result;
}

However, occasionally I still get the error which results in a Windows
dialog box appearing indicating the error.

What is the BEST way to do this type of trapping so that I don't get the
error?

thanks in advance
Back to top
Thomas Maeder [TeamB]
Guest





PostPosted: Thu Apr 19, 2007 12:22 am    Post subject: Re: log10: SING Error -> Try/Catch?? Reply with quote



Dan <Dan (AT) do (DOT) not.spam> writes:

Quote:
log10 functions where the value passed to the function is negative
results in a "LOG10: DOMAIN error" if the value is 0 then it's a
"LOG10: SING error" For example the following code will create a
DOMAIN error.


#include <math.h

double DoLogFunction(const double &val)
{
return log10(val);
}

void main()

The return type of main() has to be int.


Quote:
{
DoLogFunction(0); //SING ERROR
DoLogFunction(-1); //DOMAIN ERROR
}


Try/Catch around the 'DoLogFunction()' function call or even around
the log10 call doesn't work.

Because what the program does is causing undefined behavior, not
throwing exceptions.


Quote:
What is the BEST way to do this type of trapping so that I don't get
the error?

As for most problems, there isn't a uniform best solution.

Have you considered providing your own version of _matherr()?
Back to top
Dan
Guest





PostPosted: Tue Apr 24, 2007 6:56 pm    Post subject: Re: log10: SING Error -> Try/Catch?? Reply with quote



Quote:
The return type of main() has to be int.
Ok; I just used this as an example; of course I didn't strictly copy and

paste code, but instead just tried to make an example (I work in the
embedded world more often, and void main() is acceptable there. My
apologies.

Quote:
Because what the program does is causing undefined behavior, not
throwing exceptions.
Is there a way to catch these so that they don't go all the up to the

top of the application?

Quote:
Have you considered providing your own version of _matherr()?
How?
Back to top
Thomas Maeder [TeamB]
Guest





PostPosted: Tue Apr 24, 2007 9:12 pm    Post subject: Re: log10: SING Error -> Try/Catch?? Reply with quote

Dan <Dan (AT) do (DOT) not.spam> writes:

Quote:
The return type of main() has to be int.

Ok; I just used this as an example; of course I didn't strictly copy
and paste code, but instead just tried to make an example (I work in
the embedded world more often, and void main() is acceptable
there. My apologies.

void main() isn't acceptable anywhere. At no time in history did C or
C++ accept any return type from main() other than int.

All this isn't extremely important, but whenever somebody posts code
to a newsgroup, somebody else might use it as a (good) example; I
therefore tend to be pedantic. My apologies :-)


Quote:
Because what the program does is causing undefined behavior, not
throwing exceptions.

Is there a way to catch these so that they don't go all the up to
the top of the application?

Have you considered providing your own version of _matherr()?

How?

RTFM. Or Google. Or both.
Back to top
Alan Bellingham
Guest





PostPosted: Tue Apr 24, 2007 9:20 pm    Post subject: Re: log10: SING Error -> Try/Catch?? Reply with quote

maeder (AT) glue (DOT) ch (Thomas Maeder [TeamB]) wrote:

Quote:
void main() isn't acceptable anywhere. At no time in history did C or
C++ accept any return type from main() other than int.

Though in a freestanding implementation, it may not be required that
main() actually exist!

Quote:
All this isn't extremely important, but whenever somebody posts code
to a newsgroup, somebody else might use it as a (good) example; I
therefore tend to be pedantic. My apologies Smile

Bearing in mind the sheer volume of Herbert-Schildt-inspired code out
there, it sometimes seems like a losing battle.

Alan Bellingham
--
ACCU Conference 2008: 2-5 April 2008 - Oxford (probably), UK
Back to top
Bob Gonder
Guest





PostPosted: Tue Apr 24, 2007 9:44 pm    Post subject: Re: log10: SING Error -> Try/Catch?? Reply with quote

Dan wrote:

Quote:
Have you considered providing your own version of _matherr()?

How?

http://msdn2.microsoft.com/en-us/library/aa298453(VS.60).aspx

There is also a section in the BDS help on it.
Back to top
Bruce Salzman
Guest





PostPosted: Wed Apr 25, 2007 1:43 am    Post subject: Re: log10: SING Error -> Try/Catch?? Reply with quote

"Alan Bellingham" <alan (AT) lspace (DOT) org> wrote in message
news:lebs231ac8kcr1nvp2utompgbbt9djq1qh (AT) 4ax (DOT) com...
Quote:

Bearing in mind the sheer volume of Herbert-Schildt-inspired code
out
there, it sometimes seems like a losing battle.


The legacy of a former prog-rock keyboard player.
:^)

--
Bruce
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.