Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* c++ exception handling
@ 2004-02-06 21:47 Scott Schindler
  2004-02-09 11:03 ` Steffen Neumann
  2004-02-09 13:22 ` Falk Hueffner
  0 siblings, 2 replies; 5+ messages in thread
From: Scott Schindler @ 2004-02-06 21:47 UTC (permalink / raw)


I am trying to test an exception handling scheme in c++ on a unix machine 
(uname -a produces the following output: OSF1 *removed* V5.1 1885 alpha 
alpha)

Here is the code:

#include <exception>
#include <iostream>

int main() 
{
    	try
    	{
    	    	int numerator(100);
    	    	int denominator(0);
    	    	// Should cause an exception to occur.
    	    	int result(numerator/denominator); 
    	}
    	catch (...)
    	{
    	    	std::cout << "Exception caught by catch all.\n";
    	}

    	return 0;
}

compiling with the following command:
cxx -std strict_ansi -std strict_ansi_errors -g -O0 test.cpp

running with the following command:
a.out

produces the following output:
Floating exception


I have also tried the following example:

#include <exception>
#include <iostream>
#include <signal.h>

extern "C"
{
    	void handler(int i)
    	{
    	    	std::cout << "Exception caught by the signal handler.\n";
    	    	throw 1;
    	}
}

int main() 
{
    	sginal(SIGFPE, handler);    	

    	try
    	{
    	    	int numerator(100);
    	    	int denominator(0);
    	    	// Should cause an exception to occur.
    	    	int result(numerator/denominator); 
    	}
    	catch (...)
    	{
    	    	std::cout << "Exception caught by catch all.\n";
    	}

    	return 0;
}

Using the same compilation and running commands produces the following 
output:
Exception caught by the signal handler.
Exception caught by catch all.



I am not sure that I want to implement the second method.  Is there a 
pure c++ way of having the program catch the exception.

Thank you for your time,

Scott Schindler


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-02-09 14:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-06 21:47 c++ exception handling Scott Schindler
2004-02-09 11:03 ` Steffen Neumann
2004-02-09 13:15   ` Scott Schindler
2004-02-09 13:22 ` Falk Hueffner
2004-02-09 14:41   ` Scott Schindler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox