Results 1 to 6 of 6
Thread: Help with exception catching
- 05-29-2011, 03:44 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 11
- Rep Power
- 0
Help with exception catching
Hi i'm having trouble doing the try catch in my methods.
Could someone give me some pointers to where I can put them?
The method is written in another class, and I'm using eclipse.Java Code:public static void openFlight() { Flight Flight; String FlightID; System.out.print("\nEnter id of Flight to open: "); FlightID = sc.nextLine(); Flight = getFlight(FlightID); if (Flight == null) { System.out.printf("\nError - Flight %s not found!\n", FlightID); } else { boolean result; result = Flight.open(); if (result == true) { System.out.printf("\nFlight %s opened for boarding.\n", FlightID); } else { System.out.printf( "\nError Flight %s cannot be opened for boarding!\n", FlightID); } } }
I want it to be able to throw an exception if the flight cannot be opened, but i've tried putting it in but keeps erroring , so i'm a bit lost.
Really appreciate it.
-
Please show us the full error message and indicate which line(s) is (are) causing it.
- 05-29-2011, 03:53 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 11
- Rep Power
- 0
Actually to be honest I don't know where to put the catch, that's the problem I'm having.
I only know where to put the try
Java Code:try { public static void openFlight() { Flight Flight; String FlightID; System.out.print("\nEnter id of Flight to open: "); FlightID = sc.nextLine(); //etc...
- 05-29-2011, 03:55 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 11
- Rep Power
- 0
the catch line I'm trying to put is something like
Java Code:catch(FlightNotScheduled fnsE){System.out.println(fnsE.getMessage());
- 05-30-2011, 11:02 AM #5
Well, that isn't right either.

Suggested reading : Catching and Handling Exceptions
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 05-31-2011, 10:38 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,467
- Rep Power
- 16
Similar Threads
-
catching exceptions (hierarchy)
By kailash in forum Java ServletReplies: 2Last Post: 02-10-2011, 06:43 AM -
Help with Catching Exceptions
By javaman1 in forum New To JavaReplies: 4Last Post: 09-11-2010, 02:06 AM -
After catching the exception thrown
By scoobyrox in forum New To JavaReplies: 2Last Post: 09-05-2010, 02:29 PM -
Catching exception from another library (class)
By ezilka in forum New To JavaReplies: 15Last Post: 05-26-2010, 06:59 AM -
unreported exception IOException -- Yet I AM catching it?
By Agathorn in forum New To JavaReplies: 2Last Post: 09-18-2009, 11:22 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks