title: Flutter: Using try/catch inside Future function
body: <p>In my application I want to take image with camera, and I'm using <code>image_picker</code> library for that. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>import 'dart:io';
  
  import 'package:image_picker/image_picker.dart';
  
  Future&lt;File&gt; getImage() async {
     var image = await ImagePicker.pickImage(source: ImageSource.camera);
  
     return image;
  }
  </code></pre>
  
  <p>It works fine, but if camera is not available for some reason, then it will crash the application. So, I think we can avoid that by using it inside <code>try/catch</code> (please correct me if I'm wrong).</p>
  
  <p>I added <code>try/catch</code>, and here is the updated code:</p>
  
  <pre><code>try {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);
  
  } catch (e) {
    print(e);
  }
  return image;
  </code></pre>
  
  <p>My IDE throws error, <strong>variable <code>image</code> is not defined</strong>.</p>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>How do I use <code>try/catch</code> properly in this case?</li>
  <li>Does <code>try/catch</code> is the approach for these kind of issues?</li>
  <li>Is there any other error/exception, I should care about?</li>
  </ol>