Guest User

Untitled

a guest
Jul 22nd, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.78 KB | None | 0 0
  1. # Old Code
  2. type InvalidConnectPacket = ref object of Exception
  3. type InvalidPingPacket = ref object of Exception
  4.  
  5. raise newException(InvalidConnectPacket, "Invalid connect packet")
  6. raise newException(InvalidPingPacket, "Invalid connect packet")
  7.  
  8. # New: How do I create an Exception object to raise new exceptions like this
  9. raise newException(InvalidPacket(error: CONNECT), "Invalid connect packet")
  10. raise newException(InvalidPacket(error: PING), "Invalid connect packet")
  11.  
  12. # Pseudo code for exception embedding enum
  13. type
  14.   ControlType = enum
  15.     CONNECT = 1, PING
  16.  
  17. type InvalidPacket = ref object of Exception
  18.   error: ControlType
  19.  
  20. ## Error
  21.  
  22. Error: type mismatch: got (InvalidPacket, string)
  23. but expected one of:
  24. template newException[](exceptn: typedesc; message: string): expr
Add Comment
Please, Sign In to add comment