×

Discussion Board

Results 1 to 5 of 5

Thread: Printing Errors

  1. #1
    Regular Contributor
    Join Date
    Jan 2004
    Posts
    165

    Printing Errors

    Does anyone know how I actually output error messages to the handset, for example when I 'catch' an error in a try catch block how do I output this to the handset. It seems to work in the emulator but not on a handset.

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    What do you mean by "output errors to the handset"? Are you talking about seeing the System.out and System.err messages?

    shmoove

  3. #3
    Regular Contributor
    Join Date
    Jan 2004
    Posts
    165
    Yes, when I 'catch' an error I want to be able to print something on screen.

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Well, you need to get clever.
    For instance, if you are using a Canvas you can do something like:
    Code:
    class MyCanvas extends Canvas {
      
      // ...
      String error;
    
      void foo() {
        try {
          // something
        }
        catch (Exception e) {
          error = "Exception caught in foo(): " + e
        }
      }
    
      // ...
     
      public void paint(Graphics g) {
        // ...
        if (error != null) {
          g.drawString(error,0,0,Graphics.TOP|Graphics.LEFT);
        }
      }
    }
    You can also pop up Alerts, append StringItems to Forms, etc.

    shmoove

  5. #5
    Registered User
    Join Date
    Mar 2003
    Location
    Bremen, Germany
    Posts
    106
    You could also use the logging framework of J2ME Polish, that allows you to view plain System.out.println()-messages on your device. Any logging statements can be deactivated as well, so you can deliver a clean and small program without needing to remove all debugging code:

    http://www.j2mepolish.org

    Code:
    try {
       image = Image.createImage( url );
    } catch (IOException e) {
       //#debug error
       System.out.println("Unable to load image [" + url + "]" + e );
    }
    As you can see, you can use different logging levels such as "debug", "info", "warn", "error" or even custom levels.

    The logging framework is controlled with a simple Ant script (build.xml).

    All the best,
    Robert

Posting Permissions

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