An unexpected string to int exception.

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 17 09:09:55 PST 2016


On Wed, Feb 17, 2016 at 04:38:34PM +0000, Taylor Hillegeist via Digitalmars-d-learn wrote:
> On Wednesday, 17 February 2016 at 16:13:47 UTC, Taylor Hillegeist wrote:
> >On Wednesday, 17 February 2016 at 16:11:44 UTC, Taylor Hillegeist wrote:
> >>I think the following error message says it all.
> >>
> >>std.conv.ConvException at C:\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(2002):
> >>Unexpected '1' when converting from type string to type int
> >>
> >>I would expect that 1 would be among the group of expected items.
> >
> >Also how rude of me:
> >
> >DMD32 D Compiler v2.070.0
> >
> >code segment in question
> >+++++
> >		if(l.style.canFind("Heading")){
> >			string tmp = l.style[6..$];
> >			ON.incrementNum( to!int(tmp));
> >+++++
> 
> So my error here was i was slicing too early.
> string tmp = l.style[6..$];
> should have been:
> string tmp = l.style[7..$];
> 
> apparently std.conv parse() will say the unexpected input is not the
> one that caused the error but the character after. in this case "g1"
> only the 1 was reported.

Please file a bug, I'll look into making a fix for it.


T

-- 
Insanity is doing the same thing over and over again and expecting different results.


More information about the Digitalmars-d-learn mailing list