From c430bfcae07489ad52ae65cadee581be72dd35d1 Mon Sep 17 00:00:00 2001 From: Bobby Date: Mon, 4 Mar 2024 08:38:06 -0500 Subject: error handling --- object/object.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'object') diff --git a/object/object.go b/object/object.go index fbecf88..20deb0c 100644 --- a/object/object.go +++ b/object/object.go @@ -9,6 +9,7 @@ const ( BOOLEAN_OBJ = "BOOLEAN" NULL_OBJ = "NULL" RETURN_VALUE_OBJ = "RETURN_VALUE" + ERROR_OBJ = "ERROR" ) type Object interface { @@ -30,6 +31,10 @@ type ReturnValue struct { Value Object } +type Error struct { + Message string +} + func (i *Integer) Type() ObjectType { return INTEGER_OBJ } @@ -61,3 +66,6 @@ func (rv *ReturnValue) Type() ObjectType { func (rv *ReturnValue) Inspect() string { return rv.Value.Inspect() } + +func (e *Error) Type() ObjectType { return ERROR_OBJ } +func (e *Error) Inspect() string { return "ERROR:" + e.Message } -- cgit v1.2.3