Throw an exception but "hide" the top frame?
    Adam D. Ruppe via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Wed Dec 24 06:11:36 PST 2014
    
    
  
On Wednesday, 24 December 2014 at 13:39:00 UTC, aldanor wrote:
> (especially when many such functions have been wrapped). Is it 
> somehow possible to throw an exception "from the parent frame" 
> so the backtrace would never drop into the template body?
Since this is just passed as arguments to the constructor, you 
can ask for the same argument in your function and forward them.
>     auto check(alias func)(int x) {
Like make that
auto check(alias func)(int x, string file = __FILE__, size_t line 
= __LINE__) {
     /* snip */
        throw new Exception("%d < 0".format(result), file, line); 
// L10
The default values are auto-filled by the compiler to be the call 
site, then you pass it on to Exception so when it prints, it 
shows that,
    
    
More information about the Digitalmars-d-learn
mailing list