Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Eclipse (Java?) makes try/catch mandatory?

Eclipse (Java?) makes try/catch mandatory?

Scheduled Pinned Locked Moved Java
helpquestioncsharpjava
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Helfdane
    wrote on last edited by
    #1

    Hi, I'm usually programming in .net but now I have to do a project in java. Nothing wrong with it, but Eclipse demands try/catch blocks on sortof every call which might pose a problem, even if I have error handling in place. How do I get rid of that? I just need a quick check for something, but it even prevents me to compile it.

    private void doSomething()
    {
    Properties properties = readProperties(chooser.getSelectedFile().getCanonicalPath()); <--- compile error
    // do something with properties
    }
    private void readProperties(String location)
    {
    // do stuff including errorhandling
    }

    While the location of my errorhandling might be debatable, this is for a proof of concept app where I *know* the input is correct.

    A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)

    T G N 3 Replies Last reply
    0
    • H Helfdane

      Hi, I'm usually programming in .net but now I have to do a project in java. Nothing wrong with it, but Eclipse demands try/catch blocks on sortof every call which might pose a problem, even if I have error handling in place. How do I get rid of that? I just need a quick check for something, but it even prevents me to compile it.

      private void doSomething()
      {
      Properties properties = readProperties(chooser.getSelectedFile().getCanonicalPath()); <--- compile error
      // do something with properties
      }
      private void readProperties(String location)
      {
      // do stuff including errorhandling
      }

      While the location of my errorhandling might be debatable, this is for a proof of concept app where I *know* the input is correct.

      A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)

      T Offline
      T Offline
      TorstenH
      wrote on last edited by
      #2

      what's wrong? Exceptions need to be catched. Add the try/catch of the quick fix and go for it. If your code is fine it wont disturb you.

      regards Torsten I never finish anyth...

      H 1 Reply Last reply
      0
      • T TorstenH

        what's wrong? Exceptions need to be catched. Add the try/catch of the quick fix and go for it. If your code is fine it wont disturb you.

        regards Torsten I never finish anyth...

        H Offline
        H Offline
        Helfdane
        wrote on last edited by
        #3

        While I do agree with you, I was wondering if I could "force" a compile and run it, as I know that there won't be an exception on that line.

        A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)

        T 1 Reply Last reply
        0
        • H Helfdane

          While I do agree with you, I was wondering if I could "force" a compile and run it, as I know that there won't be an exception on that line.

          A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)

          T Offline
          T Offline
          TorstenH
          wrote on last edited by
          #4

          Java - Compiler - Building uncheck "Abort build when build problems errors occure" might "help". Still it remains to be really bad style.

          regards Torsten I never finish anyth...

          1 Reply Last reply
          0
          • H Helfdane

            Hi, I'm usually programming in .net but now I have to do a project in java. Nothing wrong with it, but Eclipse demands try/catch blocks on sortof every call which might pose a problem, even if I have error handling in place. How do I get rid of that? I just need a quick check for something, but it even prevents me to compile it.

            private void doSomething()
            {
            Properties properties = readProperties(chooser.getSelectedFile().getCanonicalPath()); <--- compile error
            // do something with properties
            }
            private void readProperties(String location)
            {
            // do stuff including errorhandling
            }

            While the location of my errorhandling might be debatable, this is for a proof of concept app where I *know* the input is correct.

            A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)

            G Offline
            G Offline
            Gerben Jongerius
            wrote on last edited by
            #5

            This is caused by the declaration of the method you are calling. It includes a throws part in the statement. If you don't wish to catch the exception, because you have error handling somewhere else in the application, then you can ignore the exception by adding a throws statement to your method.

            private void doSomething() throws IOException
            {
            Properties properties = readProperties(chooser.getSelectedFile().getCanonicalPath());
            }

            Please note this will only move the catch requirement up the call tree, meaning to whereever you are calling the doSomething method from. Which could be usefull when you have some type of generic exception handling in your code.

            H 1 Reply Last reply
            0
            • G Gerben Jongerius

              This is caused by the declaration of the method you are calling. It includes a throws part in the statement. If you don't wish to catch the exception, because you have error handling somewhere else in the application, then you can ignore the exception by adding a throws statement to your method.

              private void doSomething() throws IOException
              {
              Properties properties = readProperties(chooser.getSelectedFile().getCanonicalPath());
              }

              Please note this will only move the catch requirement up the call tree, meaning to whereever you are calling the doSomething method from. Which could be usefull when you have some type of generic exception handling in your code.

              H Offline
              H Offline
              Helfdane
              wrote on last edited by
              #6

              Thanks for your answer. This was what I've been looking for.

              A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)

              T 1 Reply Last reply
              0
              • H Helfdane

                Thanks for your answer. This was what I've been looking for.

                A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)

                T Offline
                T Offline
                TorstenH
                wrote on last edited by
                #7

                ...so you don't have code assist? this is also provided as quick tip.

                regards Torsten I never finish anyth...

                H 1 Reply Last reply
                0
                • H Helfdane

                  Hi, I'm usually programming in .net but now I have to do a project in java. Nothing wrong with it, but Eclipse demands try/catch blocks on sortof every call which might pose a problem, even if I have error handling in place. How do I get rid of that? I just need a quick check for something, but it even prevents me to compile it.

                  private void doSomething()
                  {
                  Properties properties = readProperties(chooser.getSelectedFile().getCanonicalPath()); <--- compile error
                  // do something with properties
                  }
                  private void readProperties(String location)
                  {
                  // do stuff including errorhandling
                  }

                  While the location of my errorhandling might be debatable, this is for a proof of concept app where I *know* the input is correct.

                  A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)

                  N Offline
                  N Offline
                  Nagy Vilmos
                  wrote on last edited by
                  #8

                  Further to other answers, if a catch-able exception is thrown it must be caught in java. Their are two options, try-catch or use throws so that the calling method knows it could receive the exception and must act accordingly. If it is a runtime error, say out of memory, then it does not need to be handled as you cannot predict how it will occur and build time.


                  Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                  1 Reply Last reply
                  0
                  • T TorstenH

                    ...so you don't have code assist? this is also provided as quick tip.

                    regards Torsten I never finish anyth...

                    H Offline
                    H Offline
                    Helfdane
                    wrote on last edited by
                    #9

                    I do have code assist, but for some reason all I got was a compile error, not a hint on how to disable "possible exceptions". I must admit I'm not using the standard Eclipse, but an Eclipse version which is tailored for the Sonic ESB, so maybe there's something in there which prevents it. And the tips are appreciated, as always.

                    A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups