How to learn perspective the right way?

For Perspective clients though, you also probably want to let the user know the thing didn’t work. For that I wrap my whole script content in try except blocks, with the except block calling a library script function that opens an error popup showing a custom message along with the traceback.format_exc()

6 Likes

Could you give a example

try:
   Stuff
except:
   shared.perspective.errors.displayError("Someone wrote the code bad, like this English")
#shared.perspective.errors
def displayError(msg=''):
   import traceback
   if msg != '':
      msg = "{}\r\n{}".format(msg, traceback.format_exc())
   else:
      msg = traceback.format_exc()
  
   system.perspective.openPopup('popup', 'popup', {'msg' : msg})

Sometimes you might want to check for Java errors as well, as these aren’t caught by the basic except. Especially if you have queries in your code.

from java.lang import Throwable

try:
  ...
except Throwable:
  ...
except:
  ...
3 Likes

Thank you