Community discussions

MikroTik App
Member Candidate
Member Candidate
Topic Author
Posts: 159
Joined: Mon Mar 17, 2014 11:30 am
Location: Amsterdam

Any way to get the error-string in `on-error=`

Tue May 17, 2016 9:07 am

`boen_robot` came up with this trick:
:local scripts [/system script print detail as-value]

#Create pseudo files (RouterOS can't create empty ones at will)
:foreach script in=$scripts do={
    /file print file=(($script->"name") . ".rsc")

#Wait for the files to be created "for real"
:delay 2s

#Fill the files with the script's contents
:foreach script in=$scripts do={
    /file set (($script->"name") . ".rsc") contents=($script->"source")
It failed with `failure: new contents too long`.

Now it is possible to sort of `try...catch` A.K.A. `try...except` using `on-error=`, but how to get back the error message is not in the on-error= documentation (the best documentation is actually the Catch run-time errors example as `on-error=` is not part of the `:execute` command, but part of the `:do` command).

Is there a way to get the error message?
When not: Why is that missing and where to put in a feature request?

Member Candidate
Member Candidate
Posts: 218
Joined: Fri Jul 10, 2009 10:23 am

Re: Any way to get the error-string in `on-error=`

Fri Jun 29, 2018 3:51 am


I too would love to know how to extract the actual error message.
[support@router] > { :put [:resolve]; :put "lala"
failure: dns name does not exist
In a do: on-error: setup, how can I read the "failure: dns name does not exist" into a variable so that I can report on it?

Who is online

Users browsing this forum: No registered users and 25 guests