Creating Custom Exceptions (Visual J#)

Started by sukishan, Sep 04, 2009, 03:57 PM

Previous topic - Next topic

sukishan

Creating Custom Exceptions (Visual J#)
package hks;
import System.*;
public class UseCustomExceptions
{
  public static void main()
  {
    try
    {
      Discount big_discount = new Discount(56);
    }
    catch (TooBigDiscountException ex)
    {
      Console.WriteLine("Exception Caught");
      Console.WriteLine(ex.get_Message());
    }
  }
}
public class Discount
{
  private int percent;
  public Discount(int percent) throws TooBigDiscountException
  {
    this.percent = percent;
    if (percent > 50)
      throw new TooBigDiscountException("Discount > 50%");
  }
}
public class TooBigDiscountException extends System.Exception
{
  public TooBigDiscountException(String msg)
  {
      super(msg);
  }
}
A good beginning makes a good ending

Quick Reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it has been approved by a moderator.

Name:
Email:
Verification:
Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S post or ALT+P preview