Using Exceptions to validate inputs
<p>I am trying to check whether the value passed by an user is valid constant or not. Here is the code I have written. </p>

<pre><code>enum Media_Delivery {
    Streaming, Progressive
}

public class TestMain {
    public static void main(String[] args) {
        String medi_delivery = "streaming";
        try {
            Media_Delivery.valueOf("streaming");
        } catch (IllegalArgumentException e) {
            System.out.print(e);
        }

    }

}
</code></pre>

<p>Now, in above code if the String passed is not withing the listed enum then it throws <code>IllegalArgumentException</code> which is obvious.</p>

<p>But my question is: Is this the proper way to validate? As we are using Java's exception mechanism to validate.</p>

<p>Can someone suggest a better idea or what I have coded above itself is the best option ?</p>

<p>-----EDIT--------</p>

<p>Another case which I wanted to discuss:</p>

<pre><code>

    public class TestMain {
            public static void main(String[] args) {
                String inputPassed = "2a";
                try {
                    Integer.parseInt(inputPassed);
                } catch (NumberFormatException nfe) {
                    throw new SomeUserDefinedException("Please enter only numeric values");
                }

            }

</code></pre>

<p>So is this a good idea ? Or there should be our own parsing mechanism?</p>
