Ints Inicialization and Throw statemtn

R

Rafael Veronezi

I have two simple questions...
One is about, how to verifiy if an integer variable has been initialized?
I mean, i have a private field declared as int, and a method that access
this field, and needs to test it to verify if it has been previously
initialized...
Actually i'm testing if it's value is equals to zero... Don't know is that
the way, I know I can't test it against null...

The other simple question is...
I'm using a throw statement in one of my methods...
When the method reachs the throw, I know it halt the execution of the
method, but, if the calling function treats this exception with a
try...catch, is the method being executed still halts, or continue it's
procession at the point where the exception was throw, after the successful
treatment on the try...catch?

Thanks,
Rafa
 
M

Mattias Sjögren

Rafael,
One is about, how to verifiy if an integer variable has been initialized?

ints and other value types doesn't really have an uninitialized state
(such as null for reference types).

I mean, i have a private field declared as int, and a method that access
this field, and needs to test it to verify if it has been previously
initialized...

Can't you just assign it whatever initial value you want at the point
of declaration or in a constructor? If you don't, its initial value
will be zero.

The other simple question is...
I'm using a throw statement in one of my methods...
When the method reachs the throw, I know it halt the execution of the
method, but, if the calling function treats this exception with a
try...catch, is the method being executed still halts, or continue it's
procession at the point where the exception was throw, after the successful
treatment on the try...catch?

The execution continues after the try..catch block (possibly in the
finally block if you have one) of the calling method.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top