I don't understand what's wrong with my code. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I don't understand what's wrong with my code.

public class MyClass { public static void main(String[ ] args) { try { System.out.println(bla); } catch (Exception e) { System.out.println("Error"); } } }

5th Feb 2017, 11:39 AM
Hxhxn Djxx
Hxhxn Djxx - avatar
4 Answers
+ 2
You haven't declared bla which is a compile-time error, not a runtime exception. Try/catch is for runtime.
5th Feb 2017, 11:43 AM
Blightedsage
Blightedsage - avatar
+ 1
Nope. bla isnt declared, so your code doesn't even compile. Try something like that instead: String a = null; a.length();
5th Feb 2017, 11:46 AM
Roland
0
Should outprint error
5th Feb 2017, 11:40 AM
Hxhxn Djxx
Hxhxn Djxx - avatar
0
Ok thanks both of you i understand it now
5th Feb 2017, 1:58 PM
Hxhxn Djxx
Hxhxn Djxx - avatar