# Catch Exception | from robot.run api

**URL:** <https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571>\
**Category:** Robot Framework\
**Created:** [4 August 2020 16:33 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571 "2020-08-04T16:33:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![simransinghal](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@simransinghal](https://forum.robotframework.org/u/simransinghal)\
**Post date:** [4 August 2020 16:33 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/1 "2020-08-04T16:33:52Z")

</div>

Is it possible to catch Test suit exception/error from robot.run API (In which no output.xml file is generated)?

---

<div class="post-metadata">

**Author:** ![simransinghal](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@simransinghal](https://forum.robotframework.org/u/simransinghal)\
**Post date:** [6 August 2020 10:17 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/2 "2020-08-06T10:17:01Z")

</div>

@René @aaltat any suggestions?

---

<div class="post-metadata">

**Author:** ![aaltat](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/aaltat/32/15_2.png) [@aaltat](https://forum.robotframework.org/u/aaltat)\
**Post date:** [6 August 2020 11:49 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/3 "2020-08-06T11:49:03Z")

</div>

Could you explain what problem you are trying to solve?

---

<div class="post-metadata">

**Author:** ![simransinghal](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@simransinghal](https://forum.robotframework.org/u/simransinghal)\
**Post date:** [9 August 2020 14:43 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/4 "2020-08-09T14:43:30Z")

</div>

Thanks for the response! I am writing a python script to run a given robot testcase passed as an argument. Also, variables files will be passed as an argument. Your help will be appreciable.

---

<div class="post-metadata">

**Author:** ![aaltat](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/aaltat/32/15_2.png) [@aaltat](https://forum.robotframework.org/u/aaltat)\
**Post date:** [9 August 2020 15:11 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/5 "2020-08-09T15:11:06Z")

</div>

Writing a script is pretty normal, but doesn’t not explain what problem you are trying to solve. Could you share some light on the problem?

---

<div class="post-metadata">

**Author:** ![simransinghal](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@simransinghal](https://forum.robotframework.org/u/simransinghal)\
**Post date:** [9 August 2020 15:17 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/6 "2020-08-09T15:17:36Z")

</div>

So, in the script, if I am writing the following line.

```python
from robot import run
run('/opt/oclip/conf/api-tests/SOL005/NSDManagement-API')

```

And, if lets say the file path is wrong then run is not giving any error. I want to catch such exceptions.

---

<div class="post-metadata">

**Author:** ![aaltat](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/aaltat/32/15_2.png) [@aaltat](https://forum.robotframework.org/u/aaltat)\
**Post date:** [9 August 2020 16:50 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/7 "2020-08-09T16:50:39Z")

</div>

It should return error code [https://robot-framework.readthedocs.io/en/latest/autodoc/robot.html#robot.run.run](https://robot-framework.readthedocs.io/en/latest/autodoc/robot.html#robot.run.run) which should be same as in here  
[https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#return-codes](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#return-codes)

But checking missing file is easier by using Python [https://docs.python.org/3/library/pathlib.html](https://docs.python.org/3/library/pathlib.html)

---

<div class="post-metadata">

**Author:** ![simransinghal](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@simransinghal](https://forum.robotframework.org/u/simransinghal)\
**Post date:** [14 August 2020 14:16 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/8 "2020-08-14T14:16:49Z")

</div>

Hi @aaltat thanks for redirecting me to the links.  
This is just one type of exception which I gave as an example. I want to catch all such exceptions.

When I am running the testcase file on command-line interface.

```python
robot path/testcase.robot

```

That time it is giving me the correct error that that file-path is wrong.  
But, when I am using script what I am getting is the error code through which it is really difficult to guess what is exactly wrong. I want to print the exact error that file path is wrong.

Any suggestions on what should I do?

---

<div class="post-metadata">

**Author:** ![aaltat](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/aaltat/32/15_2.png) [@aaltat](https://forum.robotframework.org/u/aaltat)\
**Post date:** [14 August 2020 16:10 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/9 "2020-08-14T16:10:51Z")

</div>

Not really good ones, for me the easiest way is to look what robot framework outputs say.

---

<div class="post-metadata">

**Author:** ![simransinghal](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@simransinghal](https://forum.robotframework.org/u/simransinghal)\
**Post date:** [14 August 2020 16:16 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/10 "2020-08-14T16:16:19Z")

</div>

But what about the cases in which the ‘output.xml’ is not generated like the one I mentioned (file path is wrong).

---

<div class="post-metadata">

**Author:** ![aaltat](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/aaltat/32/15_2.png) [@aaltat](https://forum.robotframework.org/u/aaltat)\
**Post date:** [14 August 2020 16:42 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/11 "2020-08-14T16:42:07Z")

</div>

I have found that the log messages printed in the console are pretty good and usually explains what goes wrong.

---

<div class="post-metadata">

**Author:** ![simransinghal](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@simransinghal](https://forum.robotframework.org/u/simransinghal)\
**Post date:** [14 August 2020 16:49 UTC](https://forum.robotframework.org/t/catch-exception-from-robot-run-api/571/12 "2020-08-14T16:49:18Z")

</div>

I am writing a script and is using robot.run for running the tests.

```python
from robot import run
run('/opt/oclip/conf/api-tests/SOL005/NSDManagement-API')

```

How can I get the log message in such case if something fails let’s say for example file path is not a valid one?
