Solved

ksh; trap math errors

Posted on 2006-07-17
7
1,078 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

734 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