title: Can't catch Java (Android) Exception with try-catch
body: <p>I'm a Java (Android) beginner (coming from Python) and I'm trying to catch an exception using Try-Catch as follows:</p>
  
  <pre><code>try {
      u.save();
  } catch (Exception e) {
      Log.wtf("DO THIS", " WHEN SAVE() FAILS");
  }
  </code></pre>
  
  <p>To my surprise I don't see my Log message but I still get the following error:</p>
  
  <blockquote>
    <p>09-25 10:53:32.147: E/SQLiteDatabase(7991):
    android.database.sqlite.SQLiteConstraintException: error code 19:
    constraint failed</p>
  </blockquote>
  
  <p>Why doesn't it catch the Exception? Am I doing something wrong here? All tips are welcome!</p>
  
  <p>The save() method looks as follows:</p>
  
  <pre><code>public final void save() {
      final SQLiteDatabase db = Cache.openDatabase();
      final ContentValues values = new ContentValues();
  
      for (Field field : mTableInfo.getFields()) {
          final String fieldName = mTableInfo.getColumnName(field);
          Class&lt;?&gt; fieldType = field.getType();
  
          field.setAccessible(true);
  
          try {
              Object value = field.get(this);
  
              if (value != null) {
                  final TypeSerializer typeSerializer = Cache.getParserForType(fieldType);
                  if (typeSerializer != null) {
                      // serialize data
                      value = typeSerializer.serialize(value);
                      // set new object type
                      if (value != null) {
                          fieldType = value.getClass();
                          // check that the serializer returned what it promised
                          if (!fieldType.equals(typeSerializer.getSerializedType())) {
                              Log.w(String.format("TypeSerializer returned wrong type: expected a %s but got a %s",
                                      typeSerializer.getSerializedType(), fieldType));
                          }
                      }
                  }
              }
  
              // TODO: Find a smarter way to do this? This if block is necessary because we
              // can't know the type until runtime.
              if (value == null) {
                  values.putNull(fieldName);
              }
              else if (fieldType.equals(Byte.class) || fieldType.equals(byte.class)) {
                  values.put(fieldName, (Byte) value);
              }
              else if (fieldType.equals(Short.class) || fieldType.equals(short.class)) {
                  values.put(fieldName, (Short) value);
              }
              else if (fieldType.equals(Integer.class) || fieldType.equals(int.class)) {
                  values.put(fieldName, (Integer) value);
              }
              else if (fieldType.equals(Long.class) || fieldType.equals(long.class)) {
                  values.put(fieldName, (Long) value);
              }
              else if (fieldType.equals(Float.class) || fieldType.equals(float.class)) {
                  values.put(fieldName, (Float) value);
              }
              else if (fieldType.equals(Double.class) || fieldType.equals(double.class)) {
                  values.put(fieldName, (Double) value);
              }
              else if (fieldType.equals(Boolean.class) || fieldType.equals(boolean.class)) {
                  values.put(fieldName, (Boolean) value);
              }
              else if (fieldType.equals(Character.class) || fieldType.equals(char.class)) {
                  values.put(fieldName, value.toString());
              }
              else if (fieldType.equals(String.class)) {
                  values.put(fieldName, value.toString());
              }
              else if (fieldType.equals(Byte[].class) || fieldType.equals(byte[].class)) {
                  values.put(fieldName, (byte[]) value);
              }
              else if (ReflectionUtils.isModel(fieldType)) {
                  values.put(fieldName, ((Model) value).getId());
              }
              else if (ReflectionUtils.isSubclassOf(fieldType, Enum.class)) {
                  values.put(fieldName, ((Enum&lt;?&gt;) value).name());
              }
          }
          catch (IllegalArgumentException e) {
              Log.e(e.getClass().getName(), e);
          }
          catch (IllegalAccessException e) {
              Log.e(e.getClass().getName(), e);
          }
      }
  
      if (mId == null) {
          mId = db.insert(mTableInfo.getTableName(), null, values);
      }
      else {
          db.update(mTableInfo.getTableName(), values, "Id=" + mId, null);
      }
  
      Cache.getContext().getContentResolver()
              .notifyChange(ContentProvider.createUri(mTableInfo.getType(), mId), null);
  }
  </code></pre>