title: Flutter try catch to open file
body: <p>I am trying to load an image and then display it. But it is possible the image is not yet existing because the user has not set it yet (in this case it is an image from assets that is displayed). I use a try/catch to see if the file is existing or not to avoid any error but the exception is never catched. Here the code I use :</p>
  
  <pre><code>void initState() {
      super.initState();
      widget.storage.readDirectory().then((String value) {
        Image localImage;
        try {
          localImage = Image.file(File('$value/photoProfile.jpg'));
        } catch (Exception) {
          return localImage =null ;
        }
        setState(() {
          _photoPath = localImage;
        });
      });
  }
  </code></pre>
  
  <p>And the error : </p>
  
  <pre><code>════════ Exception caught by image resource service ════════════════════════════════════════════════
  The following FileSystemException was thrown resolving an image codec:
  Cannot open file, path = '/data/user/0/com.example.flutterappdeepfashion/app_flutter/photoProfile.jpg' (OS Error: No such file or directory, errno = 2)
  </code></pre>
  
  <p>How can I solve my problem and avoid errors ?</p>
  
  <p>Thank you for your help !</p>