Article View: borland.public.cppbuilder.nativeapi
Article #2164log10: SING Error -> Try/Catch??
From: Dan
Date: Wed, 18 Apr 2007 14:55
Date: Wed, 18 Apr 2007 14:55
49 lines
2044 bytes
2044 bytes
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
Technical Details
Message-ID:
<462631f7@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder3.cambrium.nl!feeder5.cambrium.nl!feeder4.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,5a0a347bf89aa6bf,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 18 Apr 2007 09:55:42 -0500 From: Dan <Dan@do.not.spam> User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: log10: SING Error -> Try/Catch?? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 216.174.165.174 Message-ID: <462631f7@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1176908279 216.174.165.174 (18 Apr 2007 07:57:59 -0800) Lines: 49 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder3.cambrium.nl!feeder5.cambrium.nl!feeder4.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail