E
E
EgorSvinarev2021-10-02 03:30:43
Python
EgorSvinarev, 2021-10-02 03:30:43

Is it possible to redirect output of exception messages to stderr?

Hello. As far as I understand, exception messages along with the stack trace are output to stdout. I would like to receive messages in stderr. Is it possible to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor T2, 2021-10-02
@EgorSvinarev

sys.stderr.write(err_msg) - just write something to
stderr

import traceback
try:
    raise ValueError('Ошибка')
except Exception as e:
    traceback.print_exc()     # выводит в stderr

And by the way, exception messages are displayed not in stdout but in stderr
https://stackoverflow.com/questions/34046703/does-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question