# Calling Errors from Library - No Exception Raised?

**URL:** <https://forum.robotframework.org/t/calling-errors-from-library-no-exception-raised/4147>\
**Category:** Robot Framework\
**Created:** [6 July 2022 19:09 UTC](https://forum.robotframework.org/t/calling-errors-from-library-no-exception-raised/4147 "2022-07-06T19:09:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamweld](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/adamweld/32/1209_2.png) [@adamweld](https://forum.robotframework.org/u/adamweld)\
**Post date:** [6 July 2022 19:09 UTC](https://forum.robotframework.org/t/calling-errors-from-library-no-exception-raised/4147/1 "2022-07-06T19:09:48Z")

</div>

Hi there, I’m running into a problem where exceptions imported from robot.api.exceptions in my custom library are not actually raising. The keyword passes when it should be throwing an exception

I have put together a small example library and test suite to explain.

From the docstring of exceptions.py:

> Exceptions that libraries can use for communicating failures and other events.  
> These exceptions can be imported also via the top level :mod:`robot.api` package like `from robot.api import SkipExecution`.

**ErrorTest.py**

```
from robot.api import ContinuableFailure, Failure, Error, FatalError
from robot.api.logger import info, error

class ErrorTest:
    def e_fail(self):
        info('exec Failure()')
        Failure('this should fail')

    def e_cont_fail(self):
        info('exec ContinuableFailure()')
        ContinuableFailure('continuing')

    def e_error(self):
        error('exec Error()')
        Error('some text')
    
    def e_fatal_error(self):
        error('exec FatalError()')
        FatalError('message')

```

**Errors.robot**

```
***Settings***
Library libraries/ErrorTest.py

***Test Cases***
Try All Errors
    E Fail
    E Cont Fail
    E Error
    E Fatal Error

Expect Error To Fail
    Run Keyword And Expect Error * E Fail

```

**Test Execution Results**

> $ robot Errors.robot

```
==============================================================================
Errors
==============================================================================
[ERROR] exec Error()
[ERROR] exec FatalError()
Try All Errors | PASS |
------------------------------------------------------------------------------
Expect Error To Fail | FAIL |
Expected error '*' did not occur.
------------------------------------------------------------------------------
Errors | FAIL |
2 tests, 1 passed, 1 failed
==============================================================================

```

 ![Capture](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/7/7727b9d73a5c490052f9b6f4ed0f5730075b08eb.png)

---

<div class="post-metadata">

**Author:** ![adamweld](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/adamweld/32/1209_2.png) [@adamweld](https://forum.robotframework.org/u/adamweld)\
**Post date:** [7 July 2022 23:39 UTC](https://forum.robotframework.org/t/calling-errors-from-library-no-exception-raised/4147/2 "2022-07-07T23:39:20Z")

</div>

Ah, I figured it out, FatalError() et al. are not imported functions but are exceptions, and must be called with **raise**.

e.g.

```
def e_error():
        error('exec Error()')
        raise Error('some text')

```
