×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    48

    try and catch block

    how do i use the try catch block where by instead of fetching the presently displayed message it brings a message on the screen application error.
    in this code

    StringItem si,s2;
    .
    .
    private void initfirst() {


    first=new Form("Idiom (1/50)");this is number 1 of the form love sms
    StringItem si=new StringItem("","love message 1.");
    first.append(si);

    first.addCommand(NextCommand);
    first.addCommand(get_aboutCommand());
    first.addCommand(get_exitCommand());
    first.addCommand(PreviousCommand);
    first.addCommand(sendCommand);

    first.setCommandListener(this);}

    private void initsecond() {
    second=new Form("Idiom (2/50)");this is number 2 of the form love sms
    StringItem s2=new StringItem("", "love message 2.");
    second.addCommand(exitCommand);
    second.append(s2);
    second.addCommand(NextCommand);
    second.addCommand(sendCommand);
    second.addCommand(get_aboutCommand());

    second.addCommand(PreviousCommand);
    second.setCommandListener(this);

    }
    .
    .
    private void initthird() {
    third=new Form("love sms (3/50)");//this is number 3 of the form love sms(navigation between screens)
    StringItem s3=new StringItem("", "love message 3.");
    third.append(s3);

    third.addCommand(get_aboutCommand());
    third.addCommand(NextCommand);
    third.addCommand(exitCommand);
    third.addCommand(PreviousCommand);
    third.setCommandListener(this);

    }
    .
    .
    if(cmd==sendCommand){

    sendText();

    }}


    private void sendText() {
    String first =si.getText();
    sms_screen=new Form("send as sms");
    TextField to=new TextField("To:", "", 100, TextField.PHONENUMBER);
    StringItem s2=new StringItem("message", first);

    sms_screen.append(to);
    sms_screen.append(s2);

    showScreen(sms_screen);



    }
    public void showScreen(Form sms_screen) {
    Display.getDisplay(this).setCurrent(sms_screen);

    }

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,766

    Re: try and catch block

    You may want to check it in a Java tutorial.
    In short: wherever you are expecting an exception and want to response it, you surround the given piece of code with a try block, and catch the exception at the end.
    Handling an exception efficiently implies that you know what kind of exception may occur and where. In the code fragment you have posted there do not seem to be places for getting exceptions what could be responded.
    Here is a theoretical example:
    Code:
    // tf is a TextField, defined somewhere else
    try
    {
        int tfInt=Integer.parseInt(tf.getString());
        tf.setString("2*"+tfInt+"="+(tfInt*2));
    }
    catch(NumberFormatException nfe)
    {
        tf.setString("You should have written a number here");
    }
    This piece of code tries to handle the current contents of a TextField (tf) as an integer number. If it is really a number, it multiplies it by 2. If it is not a number, Integer.parseInt will throw a NumberFormatException, which is caught at the end. In this case some instruction will be written into the TextField.

Similar Threads

  1. Block applications
    By anupamvm in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 5
    Last Post: 2009-03-09, 18:40
  2. i need to block ports
    By sunny_pirate in forum Symbian
    Replies: 1
    Last Post: 2009-03-09, 12:20
  3. block
    By widetech1 in forum Symbian
    Replies: 1
    Last Post: 2008-12-05, 09:11
  4. Block Out Going SMS
    By aamitgupta in forum General Development Questions
    Replies: 1
    Last Post: 2008-04-24, 20:22
  5. SMS Block Mode
    By daverunt in forum General Messaging
    Replies: 1
    Last Post: 2004-12-15, 14:22

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×