1

I am trying to create some files programmatically in Android, which are to be saved in the phone's internal memory. My question is , which exception am I supposed to catch in the event that the phone memory completely fills up as I create and save the files?

Essentially, I want to know which exception is triggered, so that I can prevent my app from crashing in that event.

EDIT: I came to know that IOException is triggered. But how do I track whether this exception occured, because internal memory was full? Since IOException can occur for variety of reasons, how do I track this particular scenario?

SoulRayder
  • 5,072
  • 6
  • 47
  • 93
  • It will probably be an IOException with a specific message saying not enough free space or something. Why not writing a small app that simulates it? – Lior Ohana Feb 24 '14 at 11:14
  • Because the event of this actually happening is not that common, I wanted to know what exactly is thrown in such a scenario, instead of simulating it. – SoulRayder Feb 24 '14 at 11:16
  • Don't you just need to write an app that fills the phone with files and check the exception? Anyway, maybe this will help:http://stackoverflow.com/questions/8046540/java-io-io-exception-there-is-not-enough-space-on-the-disk-while-running-j2me-a – Lior Ohana Feb 24 '14 at 11:18
  • Ok but since IOexception corresponds to a broad array of exceptions, how do I catch this exception in particular? That is, how do I get to know **programmatically** that app crashed because memory was full? – SoulRayder Feb 24 '14 at 11:21
  • Edited my question accordingly – SoulRayder Feb 24 '14 at 11:22
  • Even though I don't like it, parsing the exception message is something you can do. – Lior Ohana Feb 24 '14 at 11:25
  • Yes I guess I should try that, how exactly to do that? Could you please let me know? – SoulRayder Feb 24 '14 at 11:29

3 Answers3

1

Are you looking for the OutOfMemoryError? . according to the doc

Thrown when a request for memory is made that can not be satisfied using the available platform resources. Such a request may be made by both the running application or by an internal function of the VM.

stinepike
  • 54,068
  • 14
  • 92
  • 112
  • That's what I thought.But then I got the doubt that this was for the **heap** memory pertaining to the app. What about for the **phone's internal** memory? – SoulRayder Feb 24 '14 at 11:17
  • I don't think he's talking about memory; he's talking about saving files. – Lior Ohana Feb 24 '14 at 11:18
  • oh ,, i misunderstood too .. .. then how about getting the available amount of free memory first ? – stinepike Feb 24 '14 at 11:22
  • @StinePike: Could you please shed some light as to how to do that for *phone's internal memory* in Android? :) – SoulRayder Feb 24 '14 at 11:24
  • check this so thread.. http://stackoverflow.com/questions/8133417/android-get-free-size-of-internal-external-memory ... i meant something like this – stinepike Feb 24 '14 at 11:25
1

I think this is the one you're looking for

    try{

       }catch(java.lang.OutOfMemoryError e)   {
               Log.v("Exceptional exception", e.getMessage());
  • That's what I thought.But then I got the doubt that this was for the heap memory pertaining to the app. What about for the phone's internal memory? – SoulRayder Feb 24 '14 at 11:18
0
OOM. i.e out of memory exception
Pankaj Arora
  • 10,224
  • 2
  • 37
  • 59
  • That's what I thought.But then I got the doubt that this was for the heap memory pertaining to the app. What about for the phone's internal memory? – SoulRayder Feb 24 '14 at 11:24
  • 2
    @Pankaj, please care to improve on this answer, as it does not meet the [standards](http://stackoverflow.com/help/how-to-answer) of StackOverflow's answer formats. Thanks – Ivaylo Slavov Feb 24 '14 at 11:47