Hi which exception is used for incorrect input????

hi
the valid input for my program should be like this...
12 D or 2 D something like this and if the format is not like this.. i wanna throw an
exception but don't know which one is appropriate one.. i looked up API but there are
so many....and..can't find one..so..plz help me!!~~! my code is..
StringTokenizer str = new StringTokenizer(handedCard);
                                if (str.countTokens() != 2) {
                                  throw //what shoud be here..??                 
                             }thx guys..here..

syntax: public class classname or method() throwsI don't think a class can't declare that it throws an exception.
Back to the question: You have a few choices here.
1. throw a non-runtime Exception. These must be caught or thrown. This might be what you want, but in the end, you'd just be throwing your exception back to yourself.
2. RuntimeException: Doesn't need to be caught (but can be caught) advantage is that maybe all you want to do is quit running or tell the user there was an error
3. Just check the user imput and if it's wrong ask again.

Similar Messages

  • What exception to use for incorrect file format?

    I parse a file and find out that it contains unsupported elemnet.

    You are applying a general case to specificinstance
    without knowing any of the details.Indeed I am. However, generally speaking, a method
    that throws Exception is less-than-optimal design in
    an API. I will try to illustrate my point.
    Throwing an Exception does not provide any clues to
    the user of your API about what might go wrong in the
    method call, while throwing an
    UnsupportedElementException certainly does. An
    UnsupportedElementException is much more informative
    to the user, while a plain Exception is not. A custom
    exception in this case is implicitly clear, even
    without consulting the Javadocs.Which is all true if I am writing a library. But most people do not write libraries, they write applications. In applications either exceptions are part of the process flow (explicitly caught) or they are not. The vast majority are not part of the process flow.
    >
    The only time you should create a custom exceptionis
    when you believe it will be possible for someone todo
    something intelligent with it.Are you always able to tell in advance whether the
    user of you API can do something intelligent with an
    exception? Can you make the supposition that the user
    can never do anything meaningful with the exceptions
    you throw? I am not convinced that you can, at least
    not in most of the cases.One should never ever design or code solely based on the "hope" that sometime in the future someone "might" need it. Doing that leads to code bloat, code that is hard to understand and worst of all code that is never tested.
    So unless there is a known need a special exception should not be created.
    >
    If I am creating an application that automatically
    moves data via a socket and that must move thedata,
    then I don't care why the socket failed to connect.I
    am simply going to keep retrying until it does
    connect. In this case an Exception is perfectly
    acceptable.
    On the other hand the same application might wantto
    resolve the DNS name first and simply give up if it
    can't resolve it. But still continue if the
    connection timed out. In this case at least one
    custom Exception is needed to differentiate between
    the two failure paths.Agreed. And to make the API nice and neat, write two
    meaningful custom exceptions to differentiate the
    failures. :)Nope. Again that is fine for a library. It is not needed for an application. An application has a purpose which is defined by the requirements. Adding stuff when there is neither a current requirement or when there is no expected future requirement is a bad idea.
    I have yet to meet a developer who can accurately predict the future. I have however met many who thought there code could be generalized for many possible imaginary cases that they conceived in their mind.
    And all that extra code is never tested by QA (because there are no requirements) and causes maintenance problems down the road because it is not part of the documented infrastructure.
    also it forces the user of
    you API to catch all Exceptions.That is obviously non-sensical. Regardless of the
    checked exception being used, you still have tocatch
    it.I did not mean that you force the user of your API to
    write a try-catch -block, I meant that you force the
    user of your API to catch each and every exception
    that inherits from java.lang.Exception. Even
    RuntimeExceptions; and that can be a problem.
    I have no idea what you are trying to express there.
    A checked exception must be caught regardless of what type of checked exception it is. The user might break it out but only if the user expects to do something with a specific type of exception.

  • Which function is used for  adding days to given month

    which function is used for  adding days to given month

    Hi Jagrut,
    Good ... Check out the following examples
    <b>Get a date</b>
    DATE_GET_WEEK Returns week for a date
    WEEK_GET_FIRST_DAY Returns first day for a week
    RP_LAST_DAY_OF_MONTHS Returns last day of month
    FIRST_DAY_IN_PERIOD_GET Get first day of a period
    LAST_DAY_IN_PERIOD_GET Get last day of a period
    RP_LAST_DAY_OF_MONTHS Determine last day of month
    <b>Date calculations</b>
    DATE_COMPUTE_DAY Returns a number indicating what day of the week the date falls on. Monday is returned as a 1, Tuesday as 2, etc.
    DATE_IN_FUTURE Calculate a date N days in the future.
    RP_CALC_DATE_IN_INTERVAL Add days/months to a date
    RP_CALC_DATE_IN_INTERVAL Add/subtract years/months/days from a date
    SD_DATETIME_DIFFERENCE Give the difference in Days and Time for 2 dates
    MONTH_PLUS_DETERMINE Add or subtract months from a date. To subtract a month, enter a negative value for the 'months' parameter.
    DATE_CREATE Calculates a date from the input parameters:
    Example: DATE_CREATE
    CALL FUNCTION 'DATE_CREATE'
    EXPORTING
       anzahl_jahre  = 1
       anzahl_monate = 2
       anzahl_tage   = 3
       datum_ein     = '20010101'
    IMPORTING
       datum_aus     = l_new_date.
       Result:
       l_new_date = 20020304
    Example: MONTH_PLUS_DETERMINE
    data: new_date type d.
    CALL FUNCTION 'MONTH_PLUS_DETERMINE'
    EXPORTING
    months = -5 " Negative to subtract from old date, positive to add
    olddate = sy-datum
    IMPORTING
    NEWDATE = new_date.
    write: / new_date.
    <b>Hollidays</b>
    HOLIDAY_GET Provides a table of all the holidays based upon a Factory Calendar &/ Holiday Calendar.
    HOLIDAY_CHECK_AND_GET_INFO Useful for determining whether or not a date is a holiday. Give the function a date, and a holiday calendar, and you can determine if the
    date is a holiday by checking the parameter HOLIDAY_FOUND.
    Example: HOLIDAY_CHECK_AND_GET_INFO
    data: ld_date                 like scal-datum  default sy-datum,
          lc_holiday_cal_id       like scal-hcalid default 'CA',
          ltab_holiday_attributes like thol occurs 0 with header line,
          lc_holiday_found        like scal-indicator.
    CALL FUNCTION 'HOLIDAY_CHECK_AND_GET_INFO'
      EXPORTING
        date                               = ld_date
        holiday_calendar_id                = lc_holiday_cal_id
        WITH_HOLIDAY_ATTRIBUTES            = 'X'
      IMPORTING
        HOLIDAY_FOUND                      = lc_holiday_found
      tables
        holiday_attributes                 = ltab_holiday_attributes
      EXCEPTIONS
        CALENDAR_BUFFER_NOT_LOADABLE       = 1
        DATE_AFTER_RANGE                   = 2
        DATE_BEFORE_RANGE                  = 3
        DATE_INVALID                       = 4
        HOLIDAY_CALENDAR_ID_MISSING        = 5
        HOLIDAY_CALENDAR_NOT_FOUND         = 6
        OTHERS                             = 7.
    if sy-subrc = 0 and
       lc_holiday_found = 'X'.
      write: / ld_date, 'is a holiday'.
    else.
      write: / ld_date, 'is not a holiday, or there was an error calling the function'.
    endif.
    Checking dates
    DATE_CHECK_PLAUSIBILITY Check to see if a date is in a valid format for SAP. Works well when validating dates being passed in from other systems.
    Converting dates
    DATE_CONV_EXT_TO_INT Conversion of dates to SAP internal format e.g. '28.03.2000' -> 20000328 Can also be used to check if a date is valid ( sy-subrc <> 0 )
    Function to return literal for month
    he table you want to use is T247. You can also use the function MONTH_NAMES_GET.
    You can also try table T015M. It has the month number in it's key.
    Formatting
    DATUMSAUFBEREITUNG Format date as the user settings
    Other
    MONTH_NAMES_GET It returns all the month and names in repective language.
    Good Luck and thanks
    AK

  • Can a ComboBox be used for Text Input ?

    Hi
    In Ms Access the combo box can be used for text input for creating new lines in the Database instead of just being limited to the lines already there in the drop down list. Is this possible with the combo box available in Flex 4. If it is I haven't being successful in getting it to work.
    Thanks for you help in advance
    ParaicKW

    I am using a Dataservices Commit method to write to the Database via a button on the screen
    When I type into the ComboBox's text input and click outside the combobox or on the commit button the application effectively freezes
    SituationService is a CRUD type servicePHP to MYSQL and it works with the Datagrid
    Here is the code -
    ParaicKW
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:situationservice="services.situationservice.*">
        <fx:Script>
            <![CDATA[
                import mx.controls.Alert;
                import mx.events.FlexEvent;
                protected function Situation_creationCompleteHandler(event:FlexEvent):void
                    getAllTblsituationResult3.token = situationService.getAllTblsituation();
                protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
                    getAllTblsituationResult.token = situationService.getAllTblsituation();
                protected function button1_clickHandler(event:MouseEvent):void
                    situationService.commit();
                protected function vGroup_creationCompleteHandler(event:FlexEvent):void
                    getAllTblsituationResult2.token = situationService.getAllTblsituation();
            ]]>
        </fx:Script>
        <fx:Declarations>
            <s:CallResponder id="updateSituationResult"/>
            <situationservice:SituationService id="situationService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
            <s:CallResponder id="getAllSituationResult"/>
            <s:CallResponder id="getAllTblsituationResult"/>
            <s:CallResponder id="getAllTblsituationResult2"/>
            <s:CallResponder id="getAllTblsituationResult3"/>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <mx:DataGrid x="96" y="167" id="dataGrid" creationComplete="dataGrid_creationCompleteHandler(event)" dataProvider="{getAllTblsituationResult.lastResult}" editable="true" width="470" height="237">
            <mx:columns>
                <mx:DataGridColumn headerText="ID2" dataField="ID2"/>
                <mx:DataGridColumn headerText="SITUATION" dataField="SITUATION" width="200"/>
            </mx:columns>
        </mx:DataGrid>
        <s:Button label="Commit Updates" click="button1_clickHandler(event)"/>
        <s:HGroup width="90%" height="80%" verticalCenter="20" horizontalCenter="0">
            <mx:ComboBox width="476" id="cmbSituation" creationComplete="Situation_creationCompleteHandler(event)" dataProvider="  
                     {getAllTblsituationResult3.lastResult}" labelField="SITUATION" editable="true">
            </mx:ComboBox>
            <s:TextArea width="426" id="textArea" text="{getAllTblsituationResult3.lastResult.SITUATION}"/>
            <s:Button label="Back" click="cmbSituation.selectedIndex = cmbSituation.selectedIndex-1 ; textArea.selectedIndex = textArea.selectedIndex-1"/>
            <s:Button label="Forward" click="cmbSituation.selectedIndex = cmbSituation.selectedIndex+1 ; textArea.selectedIndex = textArea.selectedIndex-1"/>
        </s:HGroup>
    </s:Application>

  • Which method is used for event creation

    Dear All,
    My client has more then one Purchase Organization. Workflow for Purchase order release very from pur org to pur org. For example - workflow WS92000030 is trigger when PO is created for India pur org where as workflow WS92000021 is trigger when PO is created for US pur org.  
    I checked and found that same Object Type - BUS2012 & event - RELEASESTEPCREATED is used in all Pur. Org PO release workflow. Also I found in Transaction code - SWETYP that Type linkage activate for  BUS2012, RELEASESTEPCREATED in all the PO workflow - WS92000030 & WS92000021.
    As per my knowledge, event can be created in various way such as Function module, Change document, General status management, Business Transaction Events etc.
    Can some one guide me, how can I found that which method is used for event creation in different pur org?
    How can I fould what is the fuctional module used for event creation if Fuctional module used for event creation. 
    For your information, I can see in T. Code - SWUO that 'Result dependent on a check function module'  for all the workflow - WS92000030, WS92000021 etc.
    Thanks in

    Hi Sahu,
    I dont think they have used the Function module or change document or any other kind of methods to trigger the workflow. This is because RELEASESTEPCREATED method is a standard method and it will be triggered by standard SAP. They can not make changes in standard sap saying RELEASESTEPCREATED should be triggered for this Purchase Org .
    Istead what i think is, they might have given the Event Condition for each workflow.
    In SWDD>> basic settings>> Start Events, we can give condition on triggering the workflow.
    Please check this.
    Regards,
    Gautham

  • Which CKM is used for moving data from Oracle to delimited file ?

    Hi All
    Please let me know Which CKM is used for moving data from Oracle to delimited file ?
    Also is there need of defining each columns before hand in target datastore. Cant ODI take it from the oracle table itself ?

    Addy,
    A CKM is a Check KM which is used to validate data and log errors. It is not going to assist you in data movement. You will need an LKM SQL to File append as answered in another thread.
    Assuming that you have a one to one mapping, to make things simpler you can duplicate the Oracle based model and create a file based model. This will take all the column definitions from the Oracle based model.
    Alternatively, you can also use an ODI tool odiSQLUnload to dump the data to a file
    HTH

  • How to specify which cert to use for software virt server?

    Is there a way to specify which certificate to use for each software virtual server? So, for example a user hitting https://somewhere.com would get the certificate for somewhere.com while the virtual server https://somewhereelse.com would use the certifcate with the name somewhereelse.com in it?

    No, this is not possible due to limitations of the underlying protocols.
    HTTP requests are sent over TCP connections which deal with IP addresses and port numbers (i.e. hardware virtual server properties), not hostnames (i.e. software virtual server properties). The HTTP protocol adds software virtual server support by allowing a client to identify the hostname (e.g. "www.iplanet.com") of the server it wishes to communicate with. This is achieved by including a "Host:" header with each HTTP request.
    Unfortunately, the SSL/TLS protocols require that the web server present its SSL/TLS certificate BEFORE the client sends its HTTP request. Since the software virtual server information is contained in the HTTP request, it is not possible for the server to select different certificates for different software virtual servers.
    You will need to use hardware virtual servers (i.e. virtual servers that have different IP addresses and/or port numbers) if you wish to use distinct SSL/TLS certificates.

  • After reopening Firefox does not remember which desktop was used for each window. Can you help, please.

    I'm using two displays and several desktops on my Mac (OS X 10.9.4).
    When I need to restart Firefox, it remembers to open windows from last session in correct display, but does not remember which desktop was used for each window. So when the application starts, it opens all windows on a desktop which is currently active instead of reopening them on desktops used during the last session. How to fix the issue?

    Hi Nerva,
    Thank you for your question, there is a add on I have been recommended to custom set up of opening windows in new monitors. It's called [https://addons.mozilla.org/en-US/firefox/addon/monitor-master/ Monitor Master].
    However, in regards to the session remembering which monitor the window was open in, in the profile folder there is a file that stores window positions and dimensions. It is called localstore.rdf.
    Please stay tuned for more investigation, as there are definitely bugs on file for similar issues. Pinpointing it is the hard part.

  • HT1918 I am trying to enter the No. Of my VISA card (which I normaly use for payments) in the billing info of my account and it is not accepted. Does anyone have any idea why?

    I am trying to enter the No. Of my VISA card (which I normaly use for payments) in the billing info of my account and it is not accepted. Does anyone have any idea why?

    JarleEkanger wrote:
    How about this? Use Delete array subset to extract chunks for averaging, and a shift register to retain the remaining array.
    It is typically not advisable to use "delete from array" in a tight loop. The constant memory reallocations due to array resizing are probably inefficient.
    Here's one simple way to do it..
    (If the number of points is not divisible by 10, the excess tail is discarded. You can easily modify that behavior if desired.)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    averages of 10.png ‏5 KB
    averages of 10.vi ‏9 KB

  • Which cable should use for Sony DV connect to iMac ?

    Which cable should use for Sony DV(IEEE 1394)connect to iMac ?

    If your iMac has just the FireWire 800 connection, you will need the 9 pin to 4 pin cable.
    http://www.cwol.com/firewire/firewire-800-1394b-cables.htm
    If your iMac has the FireWire 400 connection, you will need the 6 pin to 4 pin cable.
    http://www.radtech.us/Products/ProCableFW400800.aspx
    Links are to illustrate examples. You should be able to pick them up at most computer stores.

  • I have a Comcast system and am going through a Bose amp for sound.  The comcast box has an HDMI port which I've used for the Apple TV connection.  Nothing works! Help.

    have a Comcast system and am going through a Bose amp for sound.  The comcast box has an HDMI port which I've used for the Apple TV connection.  Nothing works! Help.

    Thanks.  Thought that would be the solution but for my wall mounted TV it's going to be a problem but many thanks for your reply.....

  • Is there a custom function available which can be used for logging errors captured in a sp in a sql table

    Is there a custom function  available which can be used for logging errors captured in a sp during and after execution in a sql table?
    Basically we  would like to utilize such function  in every sp and log errors of each sp in a error log table
    Mudassar

    Thanks .
    I was able to write this however I am thinking I am missing something
    CREATE FUNCTION testfunction1()
    RETURNS @temp_error TABLE (
    id int identity(1,1),
    procedure_name varchar(255),
    line_number int,
    error_number int,
    error_message varchar(max),
    error_state int,
    error_severity int,
    occurence_datetime datetime default current_timestamp,
    user_name sysname default suser_name(),
    login_name sysname default suser_name()
    AS
    BEGIN
    insert @temp_error(procedure_name,line_number,error_number,error_message,error_state,error_severity)
    select error_procedure(),error_line(),error_number(),error_message(),error_state(),error_severity()
    RETURN;
    END;
    CREATE TYPE test_type AS TABLE(
    id int identity(1,1),
    procedure_name varchar(255),
    line_number int,
    error_number int,
    error_message varchar(max),
    error_state int,
    error_severity int,
    occurence_datetime datetime default current_timestamp,
    user_name sysname default suser_name(),
    login_name sysname default suser_name()
    GO
    create proc usp_error_test
    @test_type AS test_type READONLY
    as
    begin
    begin try
    select 1/0
    end try
    begin catch
    select * from testfunction1(@test_type)
    end catch
    end
    Mudassar

  • Which frame is used for movie preview?

    Which frame is used for a home movie preview, takin with an iPhone 4s?  I guess the question is, is there a way to specify the frame of the movie which is used for the preview?
    -Thanks

    I would have a look at
    Gallery
    Demo or at the site of a friend of mine
    http://www.schutte.name

  • Which dictionary is used for spell check.

    Hi,
    I wanted to find out which dictionary is used for spell check? Is it Miriam Webster? My product manager and myself are curious.
    Regards.
    Ram.

    Hi Ram,
    Its ApEx Dictionary.
    Thanks
    Rana

  • Which tool is used for database designing

    Hi,
    Can you please share which tool is used for database(Oracle) designing most
    Thanks

    Kim Berg Hansen wrote:
    Personally I use brain, pen and paper for designing/modelling - then simply write scripts to create those tables.Me too.
    But of course I realize that is not the way of a modern programmer :-)No, modern programmers rely less on the brain part.
    I have heard other people saying that the (now free) [url http://www.oracle.com/technetwork/developer-tools/datamodeler/overview/index.html]SQL Developer Data Modeler is helpful for modelling. I haven't any personal experience, though.
    I have used it to reverse engineer the design resulting from the brain / pen / paper / scripts process and produce pretty pictures for the modern programmers to try and understand. It works quite well for this.

Maybe you are looking for