Solved

ksh; trap math errors

Posted on 2006-07-17
7
1,072 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ADO Memory leak with DELPHI 2007 37 181
mixString challenge 36 121
Prevent this page from creating additional dialogs. 3 531
sumHeights  challenge 17 70
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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