+ 2

Error !

public class Program { public static void main(String[] args) { String s = "admin"; byte[] bytes = s.getBytes("US-ASCII"); } } // Shows an error :- An exception must be caught and thrown..... What should I do?

5th Oct 2017, 5:33 PM
Hemant Jaiswal
Hemant Jaiswal - avatar
2 Answers
+ 14
Surround the line byte[] bytes = s.getBytes("US-ASCII"); with a try / catch statement for the exception that is specified in the error message. (throws annotation doesn't make sense here as it is the main class, you need to handle the exception).
5th Oct 2017, 5:45 PM
Tashi N
Tashi N - avatar
+ 3
Oh thanks @ Tashi
5th Oct 2017, 5:48 PM
Hemant Jaiswal
Hemant Jaiswal - avatar