Raise exception given in CLI

Hi!

My app uses several pyhton packages for calculations and I would like to show the exception given in CLI to the user. How can I do this? I found the example below, but in the example I need to define the exception myself.

Thanks for the tip!

from viktor import UserExceptionclass 
SomePythonClass:    
def calculate_block_volume(self, params):       
 width = params.input.geometry.width        
 length = params.input.geometry.length      
 height = params.input.geometry.height        

 if not isinstance(width, (int, float)):           
    raise UserException("Input 'width' is not a number!")       
 if not isinstance(length, (int, float)):           
    raise UserException("Input 'length' is not a number!")    
 if not isinstance(height, (int, float)):         
    raise UserException("Input 'height' is not a number!") 

 return width * length * height

Not really sure if I get your question right but what about:

try:
    # do things in python packages
except Exception as error_message:
    raise UserException(f"{error_message}")

2 Likes

Hi Wichard,

Thanks for your quick response. This is exactly what I need! Thanks!

Bart