What is the difference of the following code snippets?

The following one is modelled after the standard _newException_ proc
    
    
     MyError= object of CatchableError
       count:int
    ...
    proc newMyError(ct:int) : owned(ref MyError ) {.noinline.} =
       var e: owned(ref MyError)
         new(e)
         e.count= ct
         return e
    ...
    try :
      raise newMyError(3)
    except MyError as E :
      echo "caught", E.count
    
    
    Run

Is the following alternative safe, as well?
    
    
     MyError= ref object of CatchableError
       count:int
    ...
    try :
      raise MyError(count:3)
    except MyError as E :
      echo "caught ", E.count
    
    
    Run

Reply via email to