473,657 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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@O REMUS
$ 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 1705
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@O REMUS
$ 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********@mec h.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@O REMUS
$ 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********@mec h.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********@mec h.upatras.gr> wrote in message news:c4******** **@nic.grnet.gr ...

error.cpp: In constructor `A::A()':
error.cpp:1 1: 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
3174
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() ---> <cffunction name="validate" access="remote" returnType="numeric"> <cfargument name="username" required="yes" type="string" /> <cfargument name="password" required="yes" type="string" /> <cfquery name="validate" datasource="#request.dsn#">
5
854
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 (will match to firstname and lastname in SQL table). I can't figure out the syntax!!! I would like the Error msg to just display and exit the sub if the row exists. help!!!! thanks!
6
1355
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 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
4
2054
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. The function in question: 36: template <typename Container, 37: typename OutputIterator,
3
1644
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 there is an error best would be to know where. I did find PyParser_SimpleParseString which does return a node structure. If there is an error it seems to return NULL, while I did not find this documented. Th eproblem with this is that first I...
8
3144
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 developer. x = someObject as MySpecificType; x = (MySpecificType) someObject; Thanks.
1
164
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 I too like to write portable code even when not required.
9
1363
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 class
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.