# Expects a runtime error to return even though it does so

**URL:** <https://forum.codecrafters.io/t/expects-a-runtime-error-to-return-even-though-it-does-so/10267>\
**Category:** Challenges\
**Tags:** challenge:interpreter\
**Created:** [May 10, 2025, 5:11am UTC](https://forum.codecrafters.io/t/expects-a-runtime-error-to-return-even-though-it-does-so/10267 "2025-05-10T05:11:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdelshafei](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/abdelshafei/32/3574_2.png) [@abdelshafei](https://forum.codecrafters.io/u/abdelshafei)\
**Post date:** [May 10, 2025, 5:11am UTC](https://forum.codecrafters.io/t/expects-a-runtime-error-to-return-even-though-it-does-so/10267/1 "2025-05-10T05:11:33Z")

</div>

Hey all,

I believe I got a similar error to this months ago, however, this one has been puzzling me for a while now.

Whenever I test my code using the codecrafter CLI i get a “expected runtime error (exit code 70), got exit code -1” when it clearly does return a runtime error

Here are my code snippets:

[main.cpp]

```auto
   } else if(command == "run") {
        string file_contents = read_file_contents(argv[2]);

        try { // checks for any unterminated comment blocks
            Scanner scan(file_contents);
        } catch (invalid_argument& err) {
            cerr << err.what();
            return 65;
        }

        Scanner scanner(file_contents);
        if(scanner.getErrStatus())
            return 65;

        Parser parser(scanner.getTokens());
        Interpreter interpreter;

        try {
            interpreter.interpret(parser.parseStmt());
        } catch (runtime_error& err) {
            cerr << err.what();
            return 65;
        }

```

[Interpreter.cpp]

```auto
    } else if(relational == LESS) {

        if(holds_alternative<double>(lValue) && holds_alternative<double>(rValue)) {
            return get<double>(lValue) < get<double>(rValue);
        } else if(holds_alternative<int>(lValue) && holds_alternative<int>(rValue)) {
            return get<int>(lValue) < get<int>(rValue);
        }

        throw runtime_error("Operands must be numbers.");  

```

Here is the error I am getting:

```auto
[tester::#IB5] Running tests for Stage #IB5 (Evaluating Expressions - Runtime Errors: Relational Operators)
[tester::#IB5] [test-1] Running test case: 1
[tester::#IB5] [test-1] Writing contents to ./test.lox:
[tester::#IB5] [test-1.lox] "baz" < true
[tester::#IB5] [test-1] $ ./your_program.sh evaluate test.lox
[your_program] Operands must be numbers.
[tester::#IB5] [test-1] expected runtime error (exit code 70), got exit code -1
[tester::#IB5] [test-1] Test failed

```

And here is my github repo for this project:

> **[GitHub - abdelshafei/CodeInterpreter: Custom syntax interpreter](https://github.com/abdelshafei/CodeInterpreter)**
>
> Custom syntax interpreter

If anybody can help me with this, I would greatly appreciate it.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [May 11, 2025, 10:26pm UTC](https://forum.codecrafters.io/t/expects-a-runtime-error-to-return-even-though-it-does-so/10267/4 "2025-05-11T22:26:43Z")

</div>

Hey @abdelshafei, I tried running your code against the previous stages, but it’s actually no longer passing a previous stage **#EA6 (Scanning: Lexical errors)**.

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/8/88e9f042defb942b9da56323fa4ac4fa5679933a.png)

**Suggestions** :

1. Use [our CLI](https://docs.codecrafters.io/cli/installation) to test against previous stages by running:

```auto
codecrafters test --previous

```

1. Focus on fixing the early stages first, as later stages depend on them.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [May 18, 2025, 8:33am UTC](https://forum.codecrafters.io/t/expects-a-runtime-error-to-return-even-though-it-does-so/10267/6 "2025-05-18T08:33:05Z")

</div>

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [May 23, 2025, 8:33am UTC](https://forum.codecrafters.io/t/expects-a-runtime-error-to-return-even-though-it-does-so/10267/7 "2025-05-23T08:33:29Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
