[android-developers] Proper call for InputStream exceptions?

2011-01-20 Thread Joel
Hi there, so I have a problem when trying to set and read an
InputStream from a Uri with path Uri simUri = Uri.parse(content://icc/
sdn);

int readnumber = 0;

InputStream simStream = null;

//  while (keepread) {  
//Keep on reading the signal 
until
the stream ends

tv.setText(Reading...);
setContentView(tv);

try {
simStream =
this.getContentResolver().openInputStream(simUri);  //Opens an
inputstream from the Uri given from the cursor
} catch(FileNotFoundException e) {
simStream = null;
  }

try {
readnumber = simStream.read(ADCsignal);
} catch (IOException e) {
readnumber = 0;
  }

I know it is possible that it may not work because it is on a virtual
device, but is there a way to set simStream and readnumber to a value
in case of exception? I thought my code would do it but apparently
not...

Is this the proper way to call an exception by the way?

Thanks!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Proper call for InputStream exceptions?

2011-01-20 Thread TreKing
On Thu, Jan 20, 2011 at 5:50 PM, Joel jwongps...@gmail.com wrote:

 I know it is possible that it may not work because it is on a
 virtual device, but is there a way to set simStream and readnumber to a
 value in case of exception? I thought my code would do it but
 apparently not...


I'm not 100% clear on what you're asking or trying to do, but you can set
the values for both those variables in the catch or finally blocks. Of
course, if your code to open the stream failed to being with, whatever you
set them to after the fact will be fairly meaningless.


 Is this the proper way to call an exception by the way?


And exception is not something you call - it's something you throw and
catch.

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en