Exiting if null

Put your problem here if it does not fit any of the other categories.

Exiting if null

Postby cuvimo » Wed Apr 13, 2011 7:23 pm

I'm scouring through an example project that's hosted on google and I'm constantly seeing a little snippet of code that's being used to exit a function if what's being passed in is null. Is there a better way to code this instead of placing this little snippet at the beginning of every function where that variable is used?

Snippet In Question:
Code: Select all
if (gl == null) {
    return;
}


Full Code:
Code: Select all
public void Init(GL10 gl) {
    if (gl == null) {
        return;
    }
    InitTex(gl, SLWP.Bg);
}


Thanks,
Brian
cuvimo
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Mar 25, 2011 8:41 pm

Top

Re: Exiting if null

Postby imbroken » Fri Apr 15, 2011 8:58 am

yes, throw an illegalArgumentException
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests