Hi, I can't find how to create and raise a custom exception in the tutorial or 
the manual -- they _do_ cover raising built-in exceptions, but I always prefer 
to use custom exceptions so that I never "mask" built-in ones.

I've tried this: 
    
    
    type DPLError = Exception
    
    proc main(): int =
      raise newException(DPLError, "failed")
    

This fails with the error: only a 'ref object' can be raised

and this: 
    
    
    type DPLError = Exception
    let dplError = new(DPLError)
    
    proc main(): int =
      raise newException(dplError, "failed")
    

This fails with the error: type mismatch: got (ref DPLError, string) but 
expected one of: template newException[](exceptn: typedesc; message: string): 
expr

I do think that the docs should show how to do this (and if they do I haven't 
found it!)

Thanks.

Reply via email to