Java การ Return error message จาก Exception เหมือน printStackTrace
หมายถึงว่า อยากจะ return stacktrace ออกไปประมาณนี้ป่ะครับ เช่น Code
try{
int i = Integer.parseInt("xx");
}catch(Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
System.out.println(e);
}
ถ้า stacktrace เต็มๆ มันจะได้เป็น
java.lang.NumberFormatException: For input string: "xx"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)a
แต่ตัวนี้มันจะ return ออกไปไม่ได้อ่ะนะ ถ้าจะ return ออกไปได้ ก็มี 2 แบบเลือกเอาตามที่ต้องการครับ
getMessage();
return : For input string: "xx"
e.toString();
return : java.lang.NumberFormatException: For input