Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > is there a tool to remove throw list declarations?

Reply
Thread Tools

is there a tool to remove throw list declarations?

 
 
Christian Schuhegger
Guest
Posts: n/a
 
      07-23-2004
hi,

we are working on a c++ project which has a lot of thow list
specifications which in the end causes a lot of problems. now i would
like to remove them from the project. because the project has a size of
300000+ lines of code it is not so easy to do all of that manually.

therefore my question: is there a tool that you run on your sources and
which just converts the throw declarations into a comment? a tool that
only comments the declarations would be ideal, because as documentation
the declarations will still be useful.

thanks,
--
Christian Schuhegger
http://www.el-chef.de/
 
Reply With Quote
 
 
 
 
Wouter Lievens
Guest
Posts: n/a
 
      07-23-2004
"Christian Schuhegger" <(E-Mail Removed)> schreef in bericht
news:cdqan4$q8r$(E-Mail Removed)...
> hi,
>
> we are working on a c++ project which has a lot of thow list
> specifications which in the end causes a lot of problems. now i would
> like to remove them from the project. because the project has a size of
> 300000+ lines of code it is not so easy to do all of that manually.
>
> therefore my question: is there a tool that you run on your sources and
> which just converts the throw declarations into a comment? a tool that
> only comments the declarations would be ideal, because as documentation
> the declarations will still be useful.
>
> thanks,


I don't think it's a lot of work to write that yourself, in case you fail to
find such a tool.


 
Reply With Quote
 
 
 
 
JKop
Guest
Posts: n/a
 
      07-23-2004
Christian Schuhegger posted:

> hi,
>
> we are working on a c++ project which has a lot of thow

list
> specifications which in the end causes a lot of problems.

now i would
> like to remove them from the project. because the project

has a size of
> 300000+ lines of code it is not so easy to do all of that

manually.
>
> therefore my question: is there a tool that you run on

your sources and
> which just converts the throw declarations into a

comment? a tool that
> only comments the declarations would be ideal, because as

documentation
> the declarations will still be useful.
>
> thanks,



Open an editor. Tools->Replace

Replace "throw"
with "//throw"


-JKop
 
Reply With Quote
 
Christian Schuhegger
Guest
Posts: n/a
 
      07-23-2004
JKop wrote:
> Open an editor. Tools->Replace
>
> Replace "throw"
> with "//throw"

i agree that the problem looks simple, but it is not that simple

what do you do if there is a:
void AnyClass::anyMethod() throw () {
then you comment the { aswell which you don't want to do!

it is also not correct to use a regex to match for (something similar
to "throw (.*)", because you could have in your code body something like:
throw (new MyException());

i mean, obviously a task like commenting the throw declarations can be
automised, but it is not as simple as you might think. therefore, before
inventing the wheel again i would prefer to use a tool that somebody
else probably already has written.
--
Christian Schuhegger
http://www.el-chef.de/
 
Reply With Quote
 
JKop
Guest
Posts: n/a
 
      07-23-2004
Christian Schuhegger posted:

> JKop wrote:
>> Open an editor. Tools->Replace
>>
>> Replace "throw"
>> with "//throw"

> i agree that the problem looks simple, but it is not that simple
>
> what do you do if there is a:
> void AnyClass::anyMethod() throw () {
> then you comment the { aswell which you don't want to do!
>
> it is also not correct to use a regex to match for (something similar
> to "throw (.*)", because you could have in your code body something
> like:
> throw (new MyException());
>
> i mean, obviously a task like commenting the throw declarations can be
> automised, but it is not as simple as you might think. therefore,
> before inventing the wheel again i would prefer to use a tool that
> somebody else probably already has written.


Replace "throw()"
with "/* throw() */"

replace "throw ()"
with "/* throw () */"

Replace "throw ( )"
with "/* throw ( ) */"

template<class T>
void DummyThrow(T) {}

#define throw DummyThrow


-JKop
 
Reply With Quote
 
JKop
Guest
Posts: n/a
 
      07-23-2004
Make that:

template<class T>
void DummyThrow(const T&) {}


-JKop
 
Reply With Quote
 
tom_usenet
Guest
Posts: n/a
 
      07-23-2004
On Fri, 23 Jul 2004 12:50:51 GMT, JKop <(E-Mail Removed)> wrote:

>Christian Schuhegger posted:
>
>> JKop wrote:
>>> Open an editor. Tools->Replace
>>>
>>> Replace "throw"
>>> with "//throw"

>> i agree that the problem looks simple, but it is not that simple
>>
>> what do you do if there is a:
>> void AnyClass::anyMethod() throw () {
>> then you comment the { aswell which you don't want to do!
>>
>> it is also not correct to use a regex to match for (something similar
>> to "throw (.*)", because you could have in your code body something
>> like:
>> throw (new MyException());
>>
>> i mean, obviously a task like commenting the throw declarations can be
>> automised, but it is not as simple as you might think. therefore,
>> before inventing the wheel again i would prefer to use a tool that
>> somebody else probably already has written.

>
>Replace "throw()"
>with "/* throw() */"
>
>replace "throw ()"
>with "/* throw () */"
>
>Replace "throw ( )"
>with "/* throw ( ) */"
>
>template<class T>
>void DummyThrow(T) {}
>
>#define throw DummyThrow


What about legitimate uses of throw? E.g.

throw std::runtime_error("Something went wrong!");

That will become:

DummyThrow std::runtime_error("Something went wrong!");

which is obviously a syntax error.

Tom
 
Reply With Quote
 
JKop
Guest
Posts: n/a
 
      07-23-2004
First here's some sample code:


#include <stdexcept>

class AnyClass {
public:

void AnyMethod() throw();

};

void AnyClass::AnyMethod() throw ()
{
throw;
}


int main()
{
AnyClass monkey;

try
{

throw std::runtime_error("Something went wrong!");

throw AnyClass();

monkey.AnyMethod();

}
catch(...)
{
AnyClass ape;
}
}


I'm trying to get the following to work:


class DummyThrow
{
public:
template<class T>
DummyThrow& operator=(const T&) const { return *this; }
};

#define throw() /* z */

#define throw(a) /* z */

#define throw DummyThrow() =

#define try if(1)

#define catch(...) if(0)


But I can't get it to compile.


-JKop
 
Reply With Quote
 
Christian Schuhegger
Guest
Posts: n/a
 
      07-24-2004
Christian Schuhegger wrote:
> therefore my question: is there a tool that you run on your sources and
> which just converts the throw declarations into a comment? a tool that
> only comments the declarations would be ideal, because as documentation
> the declarations will still be useful.


the following perl script seems to do the job fine:

-- snip start --
$filename = $ARGV[0];
open(IN,$filename);

$text = "";
while($line = <IN>) {
$text .= $line;
}
close(IN);

$text =~ s/(throw[ \t\r\n]*\([ \t\r\n]*[A-Za-z_]+(::[A-Za-z_]+)*[
\t\r\n]*(,[ \t\r\n]*[A-Za-z_]+(::[A-Za-z_]+)*[ \t\r\n]*)*\))/\/\* $1 \*\//g;
print $text;
-- snip end --

--
Christian Schuhegger
http://www.el-chef.de/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To throw or to throw not? Emanuele D'Arrigo Python 6 11-15-2008 04:12 PM
JNI's throw new does not throw an exception yarona@m-sys.com Java 15 09-08-2005 08:36 AM
How to remove items from add/remove list please Caractucus Potts Computer Support 5 07-03-2005 10:31 PM
Is there any way to throw an exception in a finalizer? Francis Hwang Ruby 1 11-20-2003 07:59 AM
Throw Exception Vs Throw New Exception Kerri ASP .Net 2 10-27-2003 02:13 PM



Advertisments