Solved

"raise" and "exception" ...

Posted on 2003-10-27
4
201 Views
Last Modified: 2010-04-02
To C++ Experts,

   How is "raise" to do with "exceptions" ? can I have an example ?
 thanks.

 
0
Comment
Question by:meow00
  • 3
4 Comments
 
LVL 19

Assisted Solution

by:Dexstar
Dexstar earned 50 total points
ID: 9630552
meow00:

> How is "raise" to do with "exceptions" ? can I have an example ?

In C++, you don't "raise" exceptions.  You "throw" them.

     void SomeFunction()
     {
          try
          {
               int i = 5;

               if ( i < 5 )
                    throw i;
          }
          catch( int n )
          {
               cout << "Caught int Exception: " << n << endl;
          }
     }

Does that make it more clear?

Hope that helps,
Dex*
0
 
LVL 1

Author Comment

by:meow00
ID: 9630610
I see .... so what does raise do :
In the book (C++ in a nutshell): "The raise function sends a signal to the running program." But I don't really understand what it means ......
thanks.
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 50 total points
ID: 9630633
meow00:

> I see .... so what does raise do :
> In the book (C++ in a nutshell): "The raise function sends a signal to the
> running program." But I don't really understand what it means ......

I've been programming in C/C++ since 1992 or so, and I've never used that function.  So, I looked it up and found this:
     http://www.qnx.com/developer/docs/qnx_6.1_docs/neutrino/lib_ref/r/raise.html

Which will give you a sample of its usage.
But, in general, that is the "old sk00l" way of doing it.  With C++, you have exceptions, and so the signal()/raise() functions are pretty much obsolete.

Dex*
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9634621
meow00:

I'm glad that you accept my answers, but I'm sure it isn't necessary to split the points between my 2 answers, since they all go to the same person.  You should save that for when you want to split the points between two different people.  :)

Dex*
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C Language combined operators 28 114
I could not build boost code, 10 94
Need some help with Microsoft Visual Studio C++ 2003 5 64
c++, dynamic object by json 1 53
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

856 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