File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Method returns Exception ???? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Method returns Exception ????" Watch "Method returns Exception ????" New topic
Author

Method returns Exception ????

Janet Yap
Greenhorn

Joined: Mar 13, 2004
Posts: 24
HI
Can method return an Exception ??.Can anybody explain me this???.
Thanx
sp
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi sp,
yes a function can return an Exception.
a function can return any primitive /reference type.
and since Exception is a reference type.so a function can always return it.no probs.
for example run this program.

class ExcpTest
{
public static void main(String j[])
{
ExcpTest ect = new ExcpTest();
Exception e = ect.getException();
System.out.println("exception got :"+e.getMessage());
System.out.println("exception got :"+e.getMessage());

}

public Exception getException()
{
return new Exception("My Exception");
}
}

regards
deekasha
 
 
subject: Method returns Exception ????
 
Threads others viewed
Exception
A method can return an Exception .is it correct?
Execptions
Method Signature
Can getMessage() method of Exception class return Null?
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com