pythonerror-handlingpycharmbeep

Using beep sound at point of error in python


I want to add beep sound when an error occurs in python script. I know how to add windows beep after specific line e.g.

 duration = 1000  # milliseconds
    freq = 440  # Hz
     #some code here
    winsound.Beep(freq, duration)

Is it possible to enable beep whenever there is an error? I am using windows 10, python 3.6, and pycharm IDE. I couldn't find any feature in pycharm that gives audio notification on error.


Solution

  • You can catch all errors globally and beep when an error occurs:

    try:
        do_something()
    except:
        winsound.Beep(440, 1000)