title: What to put in try{}catch{} block for AsyncStorage in React Native
body: <p>I am new to React Native and databases in general. I am currently trying to make a class that gets the user's current position (latitude and longitude) and turns that into a url for Google Maps to be stored it in a database. However, whenever I try to compile my code, I get the error. It also shows me that error for storeData()</p>
  
  <pre><code>SyntaxError: C:\Users\xymlt\OneDrive\Desktop\not-arbit\components\Geolocation.js: Missing catch or finally clause (57:3)
  
    55 | 
    56 |  storeData = async () =&gt; {
  &gt; 57 |    try {
       |    ^
    58 |      await AsyncStorage.setItem
    59 |    }
    60 |  }
  </code></pre>
  
  <p>I tried searching for AsyncStorage examples about how to display data and most specifically, how to use the try catch block. I was looking at the example in <a href="https://github.com/react-native-community/react-native-async-storage/blob/master/docs/API.md#getAllKeys" rel="nofollow noreferrer">https://github.com/react-native-community/react-native-async-storage/blob/master/docs/API.md#getAllKeys</a> but it didn't offer any specific examples of what the try catch block should look like. Please help.</p>
  
  <pre><code>import React from 'react';
  import {View, Text,  StyleSheet, Image , PermissionsAndroid, Platform} from 'react-native';
  import AsyncStorage from '@react-native-community/async-storage';
  
  export default class Carpool extends React.Component {
    state = { // set current state
      currentLongitude: null, //Initial Longitude
      currentLatitude: null, //Initial Latitude
   }
   componentDidMount = () =&gt; {
    var that = this;
  
    //checl for system permissions
    if(Platform.OS === 'ios'){
      this.callLocation(that);
    }else{
      async function requestLocationPermission() {
        try {
          const granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,{
              'title': 'Location Access Required',
              'message': 'This app needs to access your location'
            }
          )
          if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            that.callLocation(that);
          } else {
            alert("Permission Denied");
          }
        } catch (err) {
          alert("err",err);
          console.warn(err)
        }
      }
      requestLocationPermission();
    }    
   }
  
   callLocation(that){ //function gives current location
      navigator.geolocation.getCurrentPosition(
         (position) =&gt; {
            const currentLongitude = JSON.stringify(position.coords.longitude); //getting the Longitude from the location json
            const currentLatitude = JSON.stringify(position.coords.latitude); //getting the Latitude from the location json
            this.storeData(currentLatitude, currentLongitude);
            that.setState({ currentLongitude:currentLongitude }); //Setting state Longitude to re re-render the Longitude Text
            that.setState({ currentLatitude:currentLatitude }); //Setting state Latitude to re re-render the Longitude Text
         },
         (error) =&gt; alert(error.message),
         { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
      );
   }
  
   componentWillUnmount = () =&gt; {
      navigator.geolocation.clearWatch(this.watchID);
   }
  
  storeData = async (lat, long) =&gt; { //return a link instead
      var url = 'geo:0,0?q=' + 'lat,long';
      try {
       await AsyncStorage.setItem('urlOne', JSON.stringify(url));
     } catch (error) {
          alert("error",error);
          console.warn(error)
     }
   }
  
   getData = async(key) =&gt; {
       try {
           const value = await AsyncStorage.getItem(key)
           if(value !== null) {
              return(JSON.parse(url));
           }
       } catch(error) {
          alert("error",error);
          console.warn(error)
       }
   }
  
   render() {
      return (
         &lt;View style = {styles.container}&gt;
            &lt;Text style = {styles.boldText}&gt;
               You are Here
            &lt;/Text&gt;
            &lt;Text style={{justifyContent:'center',alignItems: 'center',marginTop:16}}&gt;
              Longitude: {this.state.currentLongitude}
            &lt;/Text&gt;
            &lt;Text style={{justifyContent:'center',alignItems: 'center',marginTop:16}}&gt;
              Latitude: {this.state.currentLatitude}
            &lt;/Text&gt;
            {this.getData('url')}
  
         &lt;/View&gt;
      )
   }
  }
  const styles = StyleSheet.create ({
   container: {
      flex: 1,
      alignItems: 'center',
      justifyContent:'center',
      marginTop: 50,
      padding:16,
      backgroundColor:'white'
   },
   boldText: {
      fontSize: 30,
      color: 'red',
   }
  })
  </code></pre>