क्या Java में एक ही catch ब्लॉक में कई exceptions को पकड़ा जा सकता है?
सभी को नमस्कार! मैंने हाल ही में Java सीखना शुरू किया है और exception handling में एक समस्या का सामना किया। मेरे पास एक method है जो फ़ाइल पढ़ता है और strings से numbers पार्स करता है। मैं कई संभावित त्रुटियों को सही ढंग से handle करना चाहता हूँ: यदि फ़ाइल नहीं मिलती है (FileNotFoundException), यदि input-output error होता है (IOException) और यदि string कोई number नहीं है (NumberFormatException)।
अब मेरा कोड इस प्रकार दिखता है:
```java
try {
BufferedReader reader = new BufferedReader(new FileReader("data.txt"));
String line = reader.readLine();
int number = Integer.parseInt(line);
System.out.println(number);
} catch (FileNotFoundException e) {
System.out.println("फ़ाइल नहीं मिली: " + e.getMessage());
} catch (IOException e) {
System.out.println("इनपुट-आउटपुट त्रुटि: " + e.getMessage());
}