What is the standard way to handle exceptions thrown by snappy?
My code looks like this: try: sp = ProductIO.readProduct(filename) except ProductIO.readProduct.IOException as e: return e
I also tried this: try: sp = ProductIO.readProduct(filename) except RuntimeWarning as w: return w
However I am not successfully getting exceptions with ProductIO.readProduct.IOException. What class I am supposed to be using for the exceptions from ProductIO.readProduct? I want to be able to get ERRORS and WARNINGS such as those below in the exception:
WARNING: org.esa.snap.core.dataio.dimap.DimapProductReader: DimapProductReader: Unable to read file ‘/home/web/satellite/tmp/Hartbeespoort/S3A_OL_1_EFR____20171015T075647_20171015T075947_20171015T100309_0179_023_206_3420_MAR_O_NR_002.SEN3_Hartbeespoort_subset.data/solar_flux_band_21.img’ referenced by ‘solar_flux_band_21’.
After a full day of searching python documentation, the snappy API documentation, stackoverflow, etc. I still cannot seems to get the warning generated by ProductIO.readProduct into a string that I can use, or turn the warning messages into an exception using python’s warnings module…
Thanks @marpet, that is the solution I have been using. However I was hoping to be able to catch Warnings and not just exceptions, however I haven’t found a way to do that yet. Thanks for answering this probably python more than snap question!
For context I am getting a “[Failed to Read Data for level 0 and rectangle]” error from the API. Now the java exception isn’t my real issue. My issue is this “severe” warning or error or whatever it is from the API is not raising an Python exception and continues to execute the code.
Is there a way for me to explicitly set that all java exceptions should be converted into a python exception?