www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Error in object.d

reply "Alexander Panek" <alexander.panek brainsware.org> writes:
Hello,

I get this weird error...

Y:\Programming\D\XML\src>%dmd% xml.d
c:\dmd\bin\..\src\phobos\object.d(92): constructor object.Exception.this  
(char[]) does not match argument types ()
Error: expected 1 arguments, not 0

...when trying to compile...

public class XmlError : Exception
{
	this(char[] msg)
	{
		writefln(msg);
	}
}

...so I solved the problem by adding "this();" at line 91...

class Exception : Object
{
     char[] msg;

     this(); // <----------- *********** HERE ***********
     this(char[] msg);
     void print();
     char[] toString();
}

...and the compiletime-error went away. I don`t know if anybody had this  
error before, but I`ve never read about something like that in the  
newsgroup yet. Just wanted to point out that :).

Regards,
Alex

-- 
huh? did you say something? :o
Apr 01 2005
next sibling parent reply bobef <bobef_member pathlink.com> writes:
I had similar problem when named a file object.d. It did't even contain class
named object but looks like dmd doesn't like files/classes with same names as
phobos or something...

In article <opsokjqktty2yy8c chello080109082145.3.15.vie.surfer.at>, Alexander
Panek says...
Hello,

I get this weird error...

Y:\Programming\D\XML\src>%dmd% xml.d
c:\dmd\bin\..\src\phobos\object.d(92): constructor object.Exception.this  
(char[]) does not match argument types ()
Error: expected 1 arguments, not 0

...when trying to compile...

public class XmlError : Exception
{
	this(char[] msg)
	{
		writefln(msg);
	}
}

...so I solved the problem by adding "this();" at line 91...

class Exception : Object
{
     char[] msg;

     this(); // <----------- *********** HERE ***********
     this(char[] msg);
     void print();
     char[] toString();
}

...and the compiletime-error went away. I don`t know if anybody had this  
error before, but I`ve never read about something like that in the  
newsgroup yet. Just wanted to point out that :).

Regards,
Alex

-- 
huh? did you say something? :o
Apr 01 2005
parent "Alexander Panek" <alexander.panek brainsware.org> writes:
On Fri, 1 Apr 2005 20:26:31 +0000 (UTC), bobef <bobef_member pathlink.com>  
wrote:

 I had similar problem when named a file object.d. It did't even contain  
 class
 named object but looks like dmd doesn't like files/classes with same  
 names as
 phobos or something...
I think you misunderstood something; I found this "mistake" inside the object.d of *phobos*. Alex -- huh? did you say something? :o
Apr 01 2005
prev sibling next sibling parent "Ben Hinkle" <bhinkle mathworks.com> writes:
"Alexander Panek" <alexander.panek brainsware.org> wrote in message 
news:opsokjqktty2yy8c chello080109082145.3.15.vie.surfer.at...
 Hello,

 I get this weird error...

 Y:\Programming\D\XML\src>%dmd% xml.d
 c:\dmd\bin\..\src\phobos\object.d(92): constructor object.Exception.this 
 (char[]) does not match argument types ()
 Error: expected 1 arguments, not 0

 ...when trying to compile...

 public class XmlError : Exception
 {
 this(char[] msg)
 {
 writefln(msg);
 }
 }

 ...so I solved the problem by adding "this();" at line 91...
eek. If you want to throw an Exception that doesn't have an error message then you should subclass Object and not Exception. Note that it looks like a bug that you pass a message to the ctor of the XmlError and it *immediately* prints the message instead of passing it to the Exception ctor.
 class Exception : Object
 {
     char[] msg;

     this(); // <----------- *********** HERE ***********
     this(char[] msg);
     void print();
     char[] toString();
 }

 ...and the compiletime-error went away.
Presumably replaced with a linking error when you tried to use a ctor that doesn't exist?Or did you rebuild phobos?
Apr 01 2005
prev sibling parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Fri, 01 Apr 2005 21:43:22 +0200, Alexander Panek  
<alexander.panek brainsware.org> wrote:
 Hello,

 I get this weird error...

 Y:\Programming\D\XML\src>%dmd% xml.d
 c:\dmd\bin\..\src\phobos\object.d(92): constructor object.Exception.this  
 (char[]) does not match argument types ()
 Error: expected 1 arguments, not 0

 ...when trying to compile...

 public class XmlError : Exception
 {
 	this(char[] msg)
 	{
 		writefln(msg);
 	}
 }

 ...so I solved the problem by adding "this();" at line 91...

 class Exception : Object
 {
      char[] msg;

      this(); // <----------- *********** HERE ***********
      this(char[] msg);
      void print();
      char[] toString();
 }

 ...and the compiletime-error went away. I don`t know if anybody had this  
 error before, but I`ve never read about something like that in the  
 newsgroup yet. Just wanted to point out that :).
I believe your error is caused by the implicit "super" call added to your "this" in your XmlError. I believe the correct soution is:
 public class XmlError : Exception
 {
 	this(char[] msg)
 	{
super(msg);
 		writefln(msg);
 	}
 }
Exception does not have a "this()" taking no parameter, perhaps it should, perhaps it shouldn't, I am undecided. Regan
Apr 01 2005
parent reply Georg Wrede <georg.wrede nospam.org> writes:
Regan Heath wrote:
 Exception does not have a "this()" taking no parameter, perhaps it 
 should,  perhaps it shouldn't, I am undecided.
I think requiring a diagnostic message in the exception instance a Good Thing.
Apr 02 2005
parent "Regan Heath" <regan netwin.co.nz> writes:
On Sat, 02 Apr 2005 16:15:11 +0300, Georg Wrede <georg.wrede nospam.org>  
wrote:
 Regan Heath wrote:
 Exception does not have a "this()" taking no parameter, perhaps it  
 should,  perhaps it shouldn't, I am undecided.
I think requiring a diagnostic message in the exception instance a Good Thing.
You're probably right. In which case I think the real problem encountered here is the error message: "c:\dmd\bin\..\src\phobos\object.d(92): constructor object.Exception.this (char[]) does not match argument types () Error: expected 1 arguments, not 0" This error is 'suggesting' the class is at fault when it's actually the 'implicit' 'super' call to the constructor which needs fixing. I'll post this to the bugs NG. Regan
Apr 02 2005