Thread View: borland.public.cppbuilder.nativeapi
7 messages
7 total messages
Started by Dan
Wed, 18 Apr 2007 14:55
log10: SING Error -> Try/Catch??
Author: 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
Re: log10: SING Error -> Try/Catch??
Author: Thomas Maeder [TeamB]
Date: Wed, 18 Apr 2007 19:22
Date: Wed, 18 Apr 2007 19:22
39 lines
1950 bytes
1950 bytes
Dan <Dan@do.not.spam> writes:
> 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.
> {
> 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.
> 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()?
Re: log10: SING Error -> Try/Catch??
Author: Dan
Date: Tue, 24 Apr 2007 13:56
Date: Tue, 24 Apr 2007 13:56
13 lines
1496 bytes
1496 bytes
> 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. > 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?
Re: log10: SING Error -> Try/Catch??
Author: Thomas Maeder [TeamB]
Date: Tue, 24 Apr 2007 16:12
Date: Tue, 24 Apr 2007 16:12
28 lines
2069 bytes
2069 bytes
Dan <Dan@do.not.spam> writes: >> 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 :-) >> 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.
Re: log10: SING Error -> Try/Catch??
Author: Alan Bellingham
Date: Tue, 24 Apr 2007 16:20
Date: Tue, 24 Apr 2007 16:20
18 lines
1610 bytes
1610 bytes
maeder@glue.ch (Thomas Maeder [TeamB]) wrote: >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! >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 :-) 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
Re: log10: SING Error -> Try/Catch??
Author: Bob Gonder
Date: Tue, 24 Apr 2007 16:44
Date: Tue, 24 Apr 2007 16:44
9 lines
1169 bytes
1169 bytes
Dan wrote: >> 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.
Re: log10: SING Error -> Try/Catch??
Author: Bruce Salzman
Date: Tue, 24 Apr 2007 20:43
Date: Tue, 24 Apr 2007 20:43
14 lines
1404 bytes
1404 bytes
"Alan Bellingham" <alan@lspace.org> wrote in message news:lebs231ac8kcr1nvp2utompgbbt9djq1qh@4ax.com... > > 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads