phobos/std/array.d
Brad Roberts a9bc53273c merge r387:397 from candidate to trunk
-- new module std.contracts
  -- migrate callers to it where appropriate
2007-10-14 23:04:19 +00:00

41 lines
1,008 B
D

// Written in the D programming language
module std.array;
private import std.c.stdio;
import std.contracts;
class ArrayBoundsError : Error
{
private:
uint linnum;
string filename;
public:
this(string filename, uint linnum)
{
this.linnum = linnum;
this.filename = filename;
char[] buffer = new char[19 + filename.length + linnum.sizeof * 3 + 1];
auto len = sprintf(buffer.ptr,
"ArrayBoundsError %.*s(%u)", filename, linnum);
buffer = buffer[0..len];
super(assumeUnique(buffer)); // fine because buffer is unaliased
}
}
/********************************************
* Called by the compiler generated module assert function.
* Builds an ArrayBoundsError exception and throws it.
*/
extern (C) static void _d_array_bounds(string filename, uint line)
{
//printf("_d_assert(%s, %d)\n", (char *)filename, line);
ArrayBoundsError a = new ArrayBoundsError(filename, line);
//printf("assertion %p created\n", a);
throw a;
}