Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

passing a thrown exception

Thread view: 
Aryeh.Friedman@gmail.com - 13 Jan 2006 01:38 GMT
Lets say I have some method that basically says (this is a syntex
question so thats why I said basically):

public void assertError(Exception exception)
{
   if (exception)
          System.out.println("PASS");
       else
          System.out.println("FAIL");
}

and then need to do something like:

assertError(new file("bad file name"));  // or anything else that will
throw an exception

how can I force the line that throws the exception to actual apss it to
assertError so I can see if their was an exception thrown or not.

--Aryeh
James Westby - 13 Jan 2006 03:37 GMT
> Lets say I have some method that basically says (this is a syntex
> question so thats why I said basically):
[quoted text clipped - 16 lines]
>
> --Aryeh

If I understand what you're after correctly then this is my normal way
of acheiving it

try {
    someMethodCallOrSimilarThatIWouldLikeToThrowAnException();
    fail();
} catch (TheExceptionThatIWantToBeThrownHere e) {
    pass();
}

I have seen it with the fail() after the catch block, which I think
would be more robust, but I haven't come across a situation that this
caused a problem in.

If you are doing lots of similar things then this can be wrapped up in a
method to simplify the test to a single line.

Hope this helps,

James
Aryeh.Friedman@gmail.com - 13 Jan 2006 16:46 GMT
Thanks... I was aware of the above techinque my question was how to
implement it as a single method (passing the statement that may or may
not throw an exception)

--Aryeh


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.