July 03, 2010 throwing a RangeError in non-release mode | ||||
---|---|---|---|---|
| ||||
When not in release mode, accessing an out-of-bounds element in an array throws a RangeError. I would like to do the same thing in dcollections when indexing, but the only tool I know of that enables throwing an error in non-release mode is assert, and that only throws an assert error. Does anyone know how to throw an arbitrary exception on an error when not in release mode? -Steve |
July 03, 2010 Re: throwing a RangeError in non-release mode | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Steven Schveighoffer <schveiguy@yahoo.com> wrote: > When not in release mode, accessing an out-of-bounds element in an array throws a RangeError. I would like to do the same thing in dcollections when indexing, but the only tool I know of that enables throwing an error in non-release mode is assert, and that only throws an assert error. > > Does anyone know how to throw an arbitrary exception on an error when not in release mode? Untested code. Also, horrible: void throwInNonRelease( T = Exception )( lazy bool test, lazy string msg ) { try { assert( test ); } catch ( AssertError ) { throw new T( msg ); } } -- Simen |
Copyright © 1999-2021 by the D Language Foundation