www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Fix] SwitchError doesn't derive from Error

Using DMD 0.100, Windows 98SE.

I've just noticed that SwitchError's giving me the same troubles as 
AssertError was before 0.89.  Same bug, same basic fix.

BTW, while debugging this fix I discovered that the eccentric 'length' 
syntactic sugar of 0.99 has broken a bit of the Phobos code, at least in 

(I thought about using std.string.format, but then realised that if that 
one day throws a SwitchError halfway between versions then it'll recurse 

Also corrected the left over comment....


module std.switcherr;

import std.c.stdio;

class SwitchError : Error
         uint linnum;
         char[] filename;

         this(char[] filename, uint linnum)
             this.linnum = linnum;
             this.filename = filename;

             char[] buffer
               = new char[17 + filename.length + linnum.sizeof * 3 + 1];
             int count = sprintf(buffer, "Switch Default %.*s(%u)",
                 filename, linnum);


  * Called by the compiler-generated default statement in a switch block.
  * Builds a SwitchError and throws it.

extern (C) static void _d_switch_error(char[] filename, uint line)
     //printf("_d_switch_error(%s, %d)\n", cast(char *)filename, line);
     SwitchError a = new SwitchError(filename, line);
     //printf("assertion %p created\n", a);
     throw a;

My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.
Sep 15 2004