How to catch sun.awt.image.PNGImageDecoder$PNGException?

前端 未结 3 624
别那么骄傲
别那么骄傲 2021-01-25 00:04

How to catch the following exception that is printed to the error console when trying to load a corrupted PNG file:

sun.awt.image.PNGImageDecoder$PNGException: i         


        
3条回答
  •  旧巷少年郎
    2021-01-25 00:42

    As @MikeNakis said, a new Thread is spawned. In fact, ImageIcon delegates the image loading to a MediaTracker which has a spawned Thread and exposes methods to ImageIcon to get image status

    Try using getImageLoadStatus() which returns the underlying status of the image in the MediaTracker

    You can not get rid of the exception, as exceptions are catched by the `MediaTracker̀ and sent to sytem err. By the way, there is probably a mean to redirect system err elsewhere and keep your app console clean

提交回复
热议问题