hexagon logo

Is there a way to catch errors in a view macro?

I'm trying to achieve something similar to try/catch in c++ or try/except in python.
Parents
  • What if you write your macro in Python? That should allow you to use the 'try' construct.
     
    Otherwise there is quite a few functions that perform commands and return an integer (1 if successful and 0 if not). This can be used to catch errors. Here is one example:
    var set var = $_self.workdir string=(eval(GETCWD()))
    var set var=$_self.FMUdir string=(eval($file_name//'_dir'))
    var set var=$_self.createDir string=(eval(MKDIR($_self.FMUdir)))
    if cond=($_self.createDir !=1)
     var set var=$_self.msg str=("Could not create directory " //$_self.FMUdir)
      var set var=$_self.errorFlag int=(EVAL(ALERT2 (msg.self, "ERROR")))
      var del var=$_self.msg
    end
    Here the value of $_self.createDir should be 1. If the directory already exist, a zero will be returned and then a message will be sent to the user.
     
Reply
  • What if you write your macro in Python? That should allow you to use the 'try' construct.
     
    Otherwise there is quite a few functions that perform commands and return an integer (1 if successful and 0 if not). This can be used to catch errors. Here is one example:
    var set var = $_self.workdir string=(eval(GETCWD()))
    var set var=$_self.FMUdir string=(eval($file_name//'_dir'))
    var set var=$_self.createDir string=(eval(MKDIR($_self.FMUdir)))
    if cond=($_self.createDir !=1)
     var set var=$_self.msg str=("Could not create directory " //$_self.FMUdir)
      var set var=$_self.errorFlag int=(EVAL(ALERT2 (msg.self, "ERROR")))
      var del var=$_self.msg
    end
    Here the value of $_self.createDir should be 1. If the directory already exist, a zero will be returned and then a message will be sent to the user.
     
Children
No Data