phobos/std/switcherr.d
Brad Roberts eec6be69ed Merge r297:387 from candidate to trunk.
-- add std.getopt
  -- add std.variant
  -- switch strings over to be invariant rather than const
  -- hopefully the last big linux makefile overhaul
  -- fix for bug 1579: write[ln] fails for obj.toString()
  -- fix negative precision handling in std.format
  -- add some file and directory iterator helpers
  -- among other little changes here and there...
2007-10-14 09:22:50 +00:00

49 lines
1.1 KiB
D

// Written in the D programming language
module std.switcherr;
import std.stdio;
class SwitchError : Error
{
private:
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 len = sprintf(buffer.ptr, "Switch Default %.*s(%u)", filename, linnum);
super(cast(string) buffer[0..len]);
}
public:
/***************************************
* If nobody catches the Assert, this winds up
* getting called by the startup code.
*/
void print()
{
printf("Switch Default %s(%u)\n", cast(char *)filename, linnum);
}
}
/********************************************
* Called by the compiler generated module assert function.
* Builds an Assert exception 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;
}