java - Skip execution if exception thrown -
i stuck on basic. in our game have leveleditor/loader can fetch levels via url. if url points nonexistant file editor should refuse load level , stay in currentlevel, struggling basic code.
private void loadlevel(url url) { scanner in = null; try { in = new scanner(new bufferedreader(new inputstreamreader( url.openstream()))); readline(in); in.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } }
essentially, if filenotfound
thrown (or other) readline(in)
should not proceed. kinds of npe if does.
private void loadlevel(url url) { scanner in = null; try { in = new scanner(new bufferedreader(new inputstreamreader( url.openstream()))); /*if(in!=null){ readline(in); in.close(); }*/ readline(in); in.close(); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } }
edit: after @luiggimendoza's suggestion.
Comments
Post a Comment