It's not a secret anymore!
The moose likes Java in General and the fly likes Creating and using exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Creating and using exceptions" Watch "Creating and using exceptions" New topic

Creating and using exceptions

Janam Robby

Joined: Sep 16, 2008
Posts: 1
Creating exceptions and passing them to the controlling module (here method with scenarios). After an exception occurs your code should stop execution of current scenario and go to another one.

You could for example create MoviePropertiesNotSetException, IllegalAgeException, etc.

You need to have several scenarios resulting with different exceptions being thrown before finally executing a final scenario without exceptions being thrown.

My code is as below:

NOTE: Finally add another static method to the cinema class that demonstrates the usage of the cinema class. Include multiple scenarios to show how the exceptions work.
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
Did you have a question ?

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
Probably best to create a CinemaException and use it as a superclass for all other Exceptions. It is very easy to create your own Exceptions; in 99% of cases you only need to create 4 constructors, as in the Exception class itself. You can decide whether it is checked or unchecked by correctly choosing the superclass for CinemaExpression.
I agree. Here's the link:
subject: Creating and using exceptions
It's not a secret anymore!