473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Syntax Error in throw().

Hello kind people.
I hope you can you help me with the following problem.

The following snippet fails to compile with g++.
(It compiles fine with other compilers.)
All I want to do is to throw an "error" exception
when the constructor A::A() gets called. I don't
understand. Do i really have any syntax error?

I'm receiving the following error message

error.cpp: In constructor `A::A()':
error.cpp:11: parse error before `;' token
Administrator@OREMUS
$ cat error.cpp

#include <iostream>
class error {};

class A {
public:
A() throw(error);
};

A::A() throw(error) {
throw(error()); <--- HERE is the syntax error
}

int main () {
try {
A x;
} catch(error a) {
std::cout<<"Ok\n";
}
return 0;
}

Any help is appreciated.

--
e.j.s
Jul 22 '05 #1
6 1696
Euripides J. Sellountos wrote:
Hello kind people.
I hope you can you help me with the following problem.

The following snippet fails to compile with g++.
(It compiles fine with other compilers.)
All I want to do is to throw an "error" exception
when the constructor A::A() gets called. I don't
understand. Do i really have any syntax error?

I'm receiving the following error message

error.cpp: In constructor `A::A()':
error.cpp:11: parse error before `;' token
Administrator@OREMUS
$ cat error.cpp

#include <iostream>
class error {};

class A {
public:
A() throw(error);
};

A::A() throw(error) {
throw(error()); <--- HERE is the syntax error ^^^^
sorry for the uppercase.
No, I am not screaming. }
If I do the following it works.
But I don't understand....
A::A() throw(error) {
error a;
throw(a);
}

int main () {
try {
A x;
} catch(error a) {
std::cout<<"Ok\n";
}
return 0;
}

Any help is appreciated.

--
e.j.s
Jul 22 '05 #2

"Euripides J. Sellountos" <se********@mech.upatras.gr> wrote in message
news:c4**********@nic.grnet.gr...
Euripides J. Sellountos wrote:
Hello kind people.
I hope you can you help me with the following problem.

The following snippet fails to compile with g++.
(It compiles fine with other compilers.)
All I want to do is to throw an "error" exception
when the constructor A::A() gets called. I don't
understand. Do i really have any syntax error?

I'm receiving the following error message

error.cpp: In constructor `A::A()':
error.cpp:11: parse error before `;' token
Administrator@OREMUS
$ cat error.cpp

#include <iostream>
class error {};

class A {
public:
A() throw(error);
};

A::A() throw(error) {
throw(error()); <--- HERE is the syntax error


Just a guess at a workaround, how about:

throw error();

Since 'throw' is a statement and not a function. I'm not a g++ user so I
can't test this out. As you say, the original compiles/links/runs on VC7.1.

I assume that A is a simplification of some more complex situation.
Otherwise you'd be better off declaring A() private and making a call to the
constructor a compilation rather than a run-time error.

Jeff F

Jul 22 '05 #3
Euripides J. Sellountos wrote:
The following snippet fails to compile with g++.
<snip />
throw(error()); <--- HERE is the syntax error

http://gcc.gnu.org/bugs.html#fixed34
Jul 22 '05 #4
Euripides J. Sellountos wrote:
The following snippet fails to compile with g++.
(It compiles fine with other compilers.)
All I want to do is to throw an "error" exception
when the constructor A::A() gets called. I don't
understand. Do i really have any syntax error?

I'm receiving the following error message
[code..]
A::A() throw(error) {
throw(error()); <--- HERE is the syntax error
//You have extra parentheses here. Remove them and it should be ok:
throw error();
}

[code..]

--
Ahti Legonkov

Jul 22 '05 #5

"Euripides J. Sellountos" <se********@mech.upatras.gr> wrote in message news:c4**********@nic.grnet.gr...
error.cpp: In constructor `A::A()':
error.cpp:11: parse error before `;' token

Program looks OK to me (by the way, throw() is not a function, the parens
on this line are unnecessary).

Just for jollies, what happens if you rename the error class something like
MyError? Might be (this isn't supposed to happen) that some thing that
<iostream> includes on your implementation may define error.

Jul 22 '05 #6
Ron Natalie wrote:
"Euripides J. Sellountos" <se********@mech.upatras.gr> wrote in message news:c4**********@nic.grnet.gr...

error.cpp: In constructor `A::A()':
error.cpp:11: parse error before `;' token


Program looks OK to me (by the way, throw() is not a function, the parens
on this line are unnecessary).

Just for jollies, what happens if you rename the error class something like
MyError? Might be (this isn't supposed to happen) that some thing that
<iostream> includes on your implementation may define error.


Thanks everyone for the helpful responses.
It works now.

e.j.s.

--
e.j.s
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phil Powell | last post by:
I am not sure why this is producing a SQL Server related error, but w/o having an instance of SQL Server on my machine to verify anything further, can you all help me with this? <!--- validate()...
5
by: ST | last post by:
Hi, I'm sort of in a rush here...I'm sort of new to vb.net and I'm trying to write the syntax to check a sql table to see if the record already exists based on firstname and lastname text fields...
6
by: Euripides J. Sellountos | last post by:
Hello kind people. I hope you can you help me with the following problem. The following snippet fails to compile with g++. (It compiles fine with other compilers.) All I want to do is to throw...
4
by: Aaron Walker | last post by:
Greetings, I'm attempting to write my first *real* template function that also deals with a map of strings to member function pointers that is making the syntax a little tricky to get right. ...
3
by: gaston.gloesener | last post by:
I am seeking for a method to parse single lines of Python code (infact they are only formulas, so I generate a line like RESULT=<formula>). I do only want to know if the syntax is correct and if...
8
by: Smithers | last post by:
Are there any important differences between the following two ways to convert to a type?... where 'important differences' means something more profound than a simple syntax preference of the...
1
by: dizzy | last post by:
James Kanze wrote: Correct, the char const* uses are very few to worth those versions. Good idea, in my case the code is to be used only on POSIX systems but I'll keep that in mind because...
9
by: parag_paul | last post by:
Hi all I am seeing the following code in one place standalone line in some function , { (void*) new (h) Class_Name(xip, virobj, type, true); } Does it make h an object of the Class_Name...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.