Re: auto syntax bugs
Re: auto syntax bugs
- Subject: Re: auto syntax bugs
- From: Andreas Grosam <email@hidden>
- Date: Sat, 24 Sep 2005 11:16:14 +0200
On 23.09.2005, at 23:45, Markian Hlynka wrote:
Has anyone else seen this?
I have the following snip of code:
Enhancement::Enhancement(char* newname, enhancement_T newtype,
bool newstatus) throw()
{
if (strlen(newname) > (enhancement_str_length - 1) )
throw new Error("String is too big!\n");
Just a side note:
You specified an empty exception specification, which means, your function will never throw - but you explicitly throw
Error in case of an error. If this happens, the runime calls
unexpected(). This is an programming error.
I would recommend to omit non-empty exception specs at all; in rare cases, an empty exception spec might be usefull, though.
Furthermore, you should not allocate the object Error on the heap, just use
throw Error("String is too big");
In the corresponding catch clause use
catch (Error& err)
otherwise you would throw a pointer to Error, which is perfectly legal, but requires to delete the object properly somehow. And you need to catch this pointer using
catch (Error* err)
For more info about exception specs, see C++ Standard,
15 Exception Handling,
in particular 15.4 Exception Specifications
But please read this, too:
<http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=109&rl=1>
strncpy(name, newname, enhancement_str_length - 1);
// strncpy does not null-terminate if src does not fit in dest
name[enhancement_str_length - 1] = 0;
type = newtype;
status = newstatus;
}
Now, indenting on the line immediately following the throw, auto-indenting totally fails. It indents the line to start under the space following the "is". The problem seems to be the two line function header. If I change it to
Enhancement::Enhancement(char* newname, enhancement_T newtype, bool newstatus) throw()
Then everything works fine. If someone could confirm this for me, I'll file a bug. If it's just me being silly... well, then I guess I need to know that too! :-D
Thanks,
Markian
----
Early to bed and early to rise, makes a man stupid and blind in the eyes.
--Mazer Rackham
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden