Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Old Code
- type InvalidConnectPacket = ref object of Exception
- type InvalidPingPacket = ref object of Exception
- raise newException(InvalidConnectPacket, "Invalid connect packet")
- raise newException(InvalidPingPacket, "Invalid connect packet")
- # New: How do I create an Exception object to raise new exceptions like this
- raise newException(InvalidPacket(error: CONNECT), "Invalid connect packet")
- raise newException(InvalidPacket(error: PING), "Invalid connect packet")
- # Pseudo code for exception embedding enum
- type
- ControlType = enum
- CONNECT = 1, PING
- type InvalidPacket = ref object of Exception
- error: ControlType
- ## Error
- Error: type mismatch: got (InvalidPacket, string)
- but expected one of:
- template newException[](exceptn: typedesc; message: string): expr
Add Comment
Please, Sign In to add comment