'try-except function in notebook databricks

thanks for you time

I am using Databricks and I am trying to do a Try-Except function of the following type:

while True:
    try:
        sdf_report=spark.createDataFrame(df_report)
        sdf_report.write.jdbc(jdbcDash,'dbo.table_name','append') #overwrite or append
        break
    except ValueError:
         None

Unfortunately it doesn't work as I want, since it never finishes executing my notebook and I need that in case the dataframe is empty, an error does not occur and my notebook ermine 'succedded'

Please recommend me a method?

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source