Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ksh; trap math errors

Posted on 2006-07-17
7
Medium Priority
?
1,083 Views
Last Modified: 2013-12-26
How do you protect math operations like

(( result = num1 * num2 + num3 / num4 ))

from killing the program.   I can check all the variables for null values, numbers
only and zero, when important, but is there a way to skip all the checking and just trap it?

I can check for an legit result value later.

Thanks

ksh
0
Comment
Question by:hank1
7 Comments
 
LVL 5

Expert Comment

by:bastibartel
ID: 17121628
Hi hank1,
try
{
    double nom = 1.0;
    double den = 0.0;
    double res = nom/den;
}
catch (...)
{
    fprintf(stderr;"Some unknow exception occured\n");
}

Cheers!
Sebastian
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17121723
> but is there a way to skip all the checking and just trap it?
don't use a shell for math calculations, ther tons of better tools for that
0
 
LVL 1

Author Comment

by:hank1
ID: 17121794
try catch?.. in ksh?
Ok, I'd rather use perl for this stuff but this is a ksh script and that's that.  :-)
I sensing that this is a check all the vars thing.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:hank1
ID: 17121896
I came up with

result=`echo "expression" | bc`

then check the result.  Divide by zero contains the string 'divide'.  Lame,
but beats the lines and lines of checking.

 I'll delete the question.
0
 
LVL 5

Expert Comment

by:bastibartel
ID: 17123747
:-)  sry - didn't see the reference to ksh.
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 17157387
Closed, 125 points refunded.
Netminder
Site Admin
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question