aspose file tools
The moose likes Java in General and the fly likes Runtime Exception@ Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Runtime Exception@ Constructor " Watch "Runtime Exception@ Constructor " New topic
Author

Runtime Exception@ Constructor

Mohammed Yousuff
Ranch Hand

Joined: Oct 17, 2007
Posts: 198
I have a class which has a main method. i getting some input value and parsing the value in constructor. However i like to know is that the best practices to throw a run time exception in a constructor.

I did this because with out that value we can't process further.

may i know your thoughts.


My Thoughts : http://passion4java.blogspot.com
Try not to become a man of success but rather to become a man of value.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
The custom I know about is to print an error message from the main method if
  • You aren't provided the correct number of command line arguments.
  • One of the command line arguments is invalid.
  • You can obviously elaborate what followsObviously you can use that sort of error message if you get an IllegalArgumentException back from your constructor. If the information is absolutely essential, then you don't want the program to execute at all.

    Is that of any help, or have I misunderstood the problem?
     
    I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
     
    subject: Runtime Exception@ Constructor
     
    Similar Threads
    Costructor return type?
    constructor and exceptions
    Serializing a static object question and NotSerializableException
    Is needed to check the length of fields?
    constructor are playing with each other ...