Simple questions about exceptions

why use try catch with new File("filename") but not with x??

ArrayIndexOutOfBoundsException is unchecked.
IOException is checked.
http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
Here's a quick overview of exceptions:
The base class for all exceptions is Throwable. Java provides Exception and Error that extend Throwable. RuntimeException (and many others) extend Exception.
RuntimeException and its descendants, and Error and its descendants, are called unchecked exceptions. Everything else is a checked exception.
If your method, or any method it calls, can throw a checked exception, then your method must either catch that exception, or declare that your method throws that exception. This way, when I call your method, I know at compile time what can possibly go wrong and I can decide whether to handle it or just bubble it up to my caller. Catching a given exception also catches all that exception's descendants. Declaring that you throw a given exception means that you might throw that exception or any of its descendants.
Unchecked exceptions (RuntimeException, Error, and their descendants) are not subject to those restrictions. Any method can throw any unchecked exception at any time without declaring it. This is because unchecked exceptions are either the sign of a coding error (RuntimeException), which is totally preventable and should be fixed rather than handled by the code that encounters it, or a problem in the VM, which in general can not be predicted or handled.

Similar Messages

  • Simple question about mount and delay script

    Hello, I have a simple question about mounting volumes on start up.
    My computer wakes up auto - and then auto there are serveral applescript tasks (mount and start up programs)
    I use this script (daily) for serveral connections with external volumes I always need the connect to. ( In the script I use this code 3 times for other locations) I do this on start up.
    set Uname to "XXX"
    set Pword to "XXX"
    set someVolume to "afp://XXX.XXX.XXX.XXX/XXX/XXX
    mount volume someVolume as user name Uname with password Pword
    (same code for 2 other locations)
    When i do this on start up sometimes the script says there is no connection possible. I guess it's because on start up the connection isn't there. And 1 minute later when computer is total ready the connection is ok. When I run the script then It works. Just sometimes ( In the morning) 'It' want to connect but the script stops. When i do it manually(I run the script again) it works just fine.
    Is it possible that I need a delay? Can someone explain this?
    How would I make a delay handler for this script? Is that the best solution?
    Thanks in advance. This is something small i'm wondering about.
    Colin

    BTW, If you saved the script as an application +(and not as an application bundle)+ you could drop the script on to *Drop Script Backgrounder* (freeware).
    Then the script would run in the background, so, you wouldn't see it running in the Finder.
    <http://www.macupdate.com/info.php/id/7922/drop-script-backgrounder-x>
    Tom

  • A simple question about combo box

    Dear All,
    Just got a simple question about combo box: I have one of these selectors with labels based on filtered rows from a table.
    Is it possible to have one more label that would select all options?
    Like:
    Product A
    Product B
    Product C
    All Product
    Many thanks for your help!
    Gilles

    Hi Gilles,
    The purpose of ComboBox itself to select single option out of many.
    For your purpose, you may have to use "List Builder" which can accomodate 1 or more  to select.
    Please revert for more clarification if you need.
    With best wishes
    BaaRaa.

  • A simple question about performance!

    Hi! I have a simple question about performance. Suppouse that you have a servlet or a class with DB access, and you need to use a value several times in that page. What is best, to assign the value from say, a resultset or a request.getParameter() to a variable or to call the resultset or the request every time you need to retrieve that value? Which option uses less memory, which is faster, etc.?
    Hoping the best fou u
    Raul

    If you need more values from a db, the best is to open some connections (connection pool) and use the for accessing the db.
    To get the data only once, open the connection, get the data, store the data whereever you want: variable (class), hidden control (if you want to send from one page to another by request) and close the connection as quicky as possible.
    The advantage of the first method is that the most time consuming activity (connections opening) is done only once.

  • Simple question about flex and AS 3.0

    Hi, this might sound like a simple question so I apologize...
    I have both a copy of flex 2 and 3, and i want to simply code in AS
    3.0 not mxml. I referred to the help of both flex 2 and 3, and all
    i could come up with is "you can add dynamic behavior to your
    documents using actionscript", which means to me, you only write
    your functions in AS and create instances with mxml (...ugh).
    personally, i find mxml to be ugly (mainly because it looks like
    html to me), and i'd rather not use it. coming from programming in
    an IDE in Java, it seems like it would be nicer to have something
    similar, all the while having the power and cool features of flash.
    I'm not fully educated in this matter so i understand that i could
    be totally wrong.
    i mean, if i have to code in mxml, i will. i'm a web
    programmer for a living, and if a more experience programmer said
    something like "if you don't code mxml in flex, you'll never get a
    job coding in flex", i would trust the advice, and learn the ugly
    code. :)
    yes, i do have Flash cs3, it's great but it seems like a pain
    to me the way you organize classes.... i've only seen a few
    tutorials, ones that explain how you cannot simply import a custom
    class, you have tell your movie to link to it, put it in the same
    directory, or manually name the package, it's sort of confusing.
    my main point here is that i'm very eager to start building
    apps in straight AS 3.0 instead of using flash cs3 (for some
    projects), and it would be cool to get some help or be pointed in
    the right direction.
    to simplify:
    can i write AS 3.0 and only as 3.0 in flex 2 or 3? how? can
    you link me to a tutorial? any advise?
    thanks!

    Hey William, thanks for the post. It's a great coincidence
    because I'm reading that book as well. I'm about half way through
    it, and I love it. I installed mxmlc on my linux box and am writing
    pure AS 3 apps. I think that's the way to go, though I know it's
    not for everybody.
    My problem with mxml is that it has a weird syntax for
    function calls, and it's not as 'intuitive' for a person like me,
    who came from C++ and Java programming in the past. I like writing
    programs in the C++ and Java style syntax, and since so many other
    languages use a similar syntax, I don't see any reason to learn the
    nuances of mxml, unless I was getting paid to do it. As far as I
    can tell there is no benefit.
    I hate using Flash to write flash apps as well, I feel like
    they become messy and confusing, especially when trying to write an
    OOP application. I only use it if I want to move an object in a
    very specific way and can't do it with the Tween methods.

  • A simple Question about % in CR Chart!

    Hi, I have another simple question.
    When i use SQL to storage data and wanna Crystal Report to display the data in chart using %
    which data type should i use?
    float or string?
    and I found when i use 0.12 as 12% in database , It could not display in Crystal Report line chart normally.
    What should I do??
    Please Help!!!
    Thank you VERY MUCH!!!

    If you have the datatype as string from your database then try adding the string field as a summary field in chart and select maximum instead of count and if you have them in number format then you can directly select the percentage in chart.
    Regards,
    Raghavendra

  • Simple question about generate proxy

    Hi guys...
    This is a simple but a truly simple question....
    When trying to create a proxy from our messages interfaces using SPROXY, i'm not able to get the Software component versions that were used from the sld...
    Do I have to export them? Or import them?

    Hi Goncalo,
    Check if it helps...
    Re: SW component version not visible in SPROXY
    Regards
    Anand

  • Simple question about JAVA path

    Hi. I have a simple question , but I spent several hours trying to find an answer.
    How do I know the location of the java executable which is used by Concurrent Manager.
    I already know that running which java under application user will not give me the correct answer

    Maybe you can try like this:
         public String getPath(){
              Class cls=getClass();
              String className=cls.getName();
              String packageName=cls.getPackage().getName();
              System.out.println(className);
              System.out.println(packageName);
              String newClassName=className.replaceAll("\\.", "/");
              String resouceName=newClassName+".class";
              System.out.println(resouceName);
              URL url;
              url=cls.getClassLoader().getResource(resouceName);
              String path="";
              path=url.getFile();
              return path;
         }

  • A very simple question about WF

    hi experts
    I would like to ask a question about workflow
    as u may know there is 'Loop' step in workflow, but I am confused when should I use Loop?
    Is this step used for processing internal table?  if yes, why shouldn't I create a custom BOR method and pass the entire internal table to the method?
    many thanks

    hi
    loop step for not process the internal table,
    this is used to process the some steps repetely until condition True or False.
    we have two loop steps is there
    WHILE AND UNTIL.
    Thanks
    sitaram

  • Simple question about telnet and characters

    Hi all,
    We've installed for the first time a SUN machine. So i think it's for a SUN expert a very simple question.
    Normally when i type a special character it will be dispayed like " � " [alt+132]
    But when i use a telnet session and i type "alt+132" i get a "d" and not "�".
    Does someone know where i must start to find out how this works ?
    Thanks you very much.
    ESP

    This is probably related to the locale your server is in. I don't remember the default locale a box is installed in if you don't specify. I think its "C". I use the UTF-8 or en_US.ISO8859-1 locales at home. At work, usually C but sometimes applications may require UTF-8. BEA Weblogic required this for a project a while back. This is defined in /etc/init/tz.

  • Maybe a simple question about M2T ?

    Hi
    I record in HDV on the JVC GY 101.
    I store on the Focus Enhancements DR HD100 Hard disk recorder.
    The footage I have is in HDV 25frames Progressive.
    The hard disk stores as m2t file and I seem to need to use Mpeg streamclip to convert for Final Cut Pro HD.
    I have a few questions about this.
    1) What should i convert to with mpeg streamclip ? mov, dv m2v etc etc
    2) What setting should I have on FCP with regards to screen size ? The converted clips are 1280x720. When I choose this setting on the sequence, I end up with small black bars left and right of the video on the canvas ???
    3) I will also later have to add some digi beta footage which will be PAL, 720x576 Anamorphic.
    4) What is the best resolution for me here ?
    5) And will the quality of the original m2t file be downgraded by the mpeg streamclip ?
    Thanks so much for your help
    All the best
    Simon

    HDV isn't an "edit-friendly" format, meaning: HDV uses inter-frame compression, combined with a long group-of-pictures (GOP) of 15 frames (12 frames in PAL-equivalent). In intra-frame compression (as in DV, DVCPRO HD, etc.), each video frame is a complete image that stands alone. Inter-frame compression (which is also used in DVDs) uses only a limited number of complete image frames, the GOP determines that number. So, in HDV for example, with a GOP of 15 frames, 1 second of 30fps video contains only 2 complete frames, while the other 28 frames are determined by calculations used in conjunction with the Bi-directional ('B') and Predicted ('P') frames, which contain partial information on the changes in the video in between the 'I' frames which contain whole images. This process, of course, requires much more computer processing power than when editing DV, DVCPRO HD, Uncompressed, etc.
    Editing video streams such as HDV (and XDCAM HD) is made difficult by the reduced number of I-frames. For example, if you make a cut in between the I-frames in the video clip, the computer has to then recalculate new I-frames that are placed at both sides of the cut. Converting on capture/after import to an intra-frame codec like DVCPRO HD, ProRes 422, or Uncompressed will reduce processing power and increase real-time performance, as well as give better performance when adding effects and performing compositing like chroma-keying.
    A common rule of thumb in professional applications is to acquire in HDV, XDCAM HD, etc., but capture and edit in DVCPRO HD, ProRes 422, or even Uncompressed. Native HDV editing is not taboo by any means; it's just not as easy or robust -- especially with the LONG render times. Depending on what kind of work you do (and of course personal preference), you may not see much benefit by transcoding to another format.
    Are you suggesting i have to convert each clip after capture?
    Unless you have an HDV deck with HD-SDI and a capture card, you would have to convert each clip. Batch-conversion would be very useful for that.
    Hope that helps.
    tim

  • A simple question about DAQ data sampling

    Hi all:
    Now I meet a very basic question about DAQ sampling.  I am using NI PCI-6040E DAQ card, SCXI-1001 chasis, SCXI-1102, SCXI1300 terminal block, and SCXI1160 relay module.
    I am not sure , is it possible if I want to test a voltage (1 volt) on a resistor. Now I am connecting the Ch0+ to resistor+ (24 volt), and connecting Ch0- to resistor-(23 volt). So the voltage between resistor+ and resistor- should be 1volt.  Actually, It is working at the first, but after I want to test 9 channels based on this connection. The Measurement & Automation can't read data from the DAQ card. (when I test it by multimeter, I can get the voltage data on the Ch0+ and Ch0- of SCXI1300 terminal block).
    That's strange, does anybody know what' s wrong about it?/
    Thanks a lot

    Hi hanwei,
    According to the specifications of the PCI 6040E (page 3), the input signal and common mode voltage should never exceed 11V from ground.  I believe this is the reason you are able to measure the potential of a battery but not the 24V signal (even though the differential value is only 1V). 
    Best Regards
    Hani R.
    Applications Engineer
    National Instruments

  • Just simple question about java HTTP session mechanism...

    I have one simple question regarding the java HTTP Session Mechanism.
    1) Is there another alternative for the HTTP Session ? If have, what the alternative?
    2) I have been acknowledge that HTTP session is same as cookie system and others say have many different, where is the different..
    thanks

    1) You can always do your own session handling. But why bother when there is one there for you?
    2) The issue with sessions is how to identify the user from the request. Each session gets given a session id. The user has to send that session id with every request they make.
    The standard way is to use a session cookie, which only lasts as long as the browser session. The cookie with the JSESSIONID is sent with every request, thus the server can identify which session a user is in from their cookie.
    Of course you cannot assume that the browser will support cookies, so you need to encode all URLs with the method response.encodeURL(). That method puts the session id into the URL if the browser does not support cookies, or they have them switched off.

  • Question about Exception Error

    I'm writing a small PBE program for a class project and I keep getting an InvalidKeySpecException that claims my char[ ] is not ASCII. Now I am under the impression that when a char value is entered it's in ASCII values... I've only put up a piece of my code, if needed I can put up the rest, it's fairly simple and easy to follow.
    here is my terminal output (with a number of debug outputs):
    Encryption Program Started
    Getting Password
    Input password (32 character max):
    hello
    Holdspot is: 6
    Pass: hello
    Holder: (shows string of char (0) values, verifies that the array was cleared)
    Done getting password, pass is:
    hello
    Creating PBEKeySpec
    My keySpec value is: hello
    Creating Salt
    createSalt entered
    Done getting salt
    Creating PBEParameterSpec
    setParams entered
    My iteration field is: 1500
    Done getting param
    My param iterations are: 1500
    Creating SecretKey
    createKey Entered
    My keySpec value is: hello
    InvalidKeySpecException: Password is not ASCII
    java.security.spec.InvalidKeySpecException: Password is not ASCII
         at com.sun.crypto.provider.PBEKey.<init>(DashoA6275)
         at com.sun.crypto.provider.PBEKeyFactory.engineGenerateSecret(DashoA6275)
         at javax.crypto.SecretKeyFactory.generateSecret(DashoA6275)
         at Cryptography.createKey(Cryptography.java:141)
         at Cryptography.main(Cryptography.java:265)
         at __SHELL3.run(__SHELL3.java:7)
         at bluej.runtime.ExecServer.vmSuspend(ExecServer.java:178)
         at bluej.runtime.ExecServer.main(ExecServer.java:143)
    java.security.spec.InvalidKeySpecException: Password is not ASCII
         at com.sun.crypto.provider.PBEKey.<init>(DashoA6275)
         at com.sun.crypto.provider.PBEKeyFactory.engineGenerateSecret(DashoA6275)
         at javax.crypto.SecretKeyFactory.generateSecret(DashoA6275)
         at Cryptography.createKey(Cryptography.java:141)
         at Cryptography.main(Cryptography.java:265)
         at __SHELL4.run(__SHELL4.java:7)
         at bluej.runtime.ExecServer.vmSuspend(ExecServer.java:178)
         at bluej.runtime.ExecServer.main(ExecServer.java:143)
    here is my code to get the char array input:
        private char[] getPass () throws IOException{
            System.out.println("Input password (32 character max):");
            char[] holder = new char[maxChar];
            int holdspot=0;
            while ((holder[holdspot++] = (char) System.in.read()) != '\n') {};
            //Debug
            System.out.println("Holdspot is: "+holdspot);
            //End Debug
            char[] pass = new char[holdspot];
            System.arraycopy (holder, 0, pass, 0, holdspot);
            //clear our holder array
            for (int i=0; i<holder.length;i++){
                holder=0;
    //Debug
    System.out.print("Pass: ");
    for (int i=0; i<holdspot;i++){
    System.out.print(pass[i]);
    System.out.print("\n");
    System.out.print("Holder: ");
    for (int i=0; i<holder.length;i++){
    System.out.print(holder[i]);
    System.out.print("\n");
    //End Debug
    //Comment back in for final version, screen clear
    //System.out.flush();
    return (pass);
    here is my code at the point where the exception is thrown:
        private SecretKey createKey(PBEKeySpec keySpec)
        throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException{
            //Debug
            System.out.println("createKey Entered");
            char[] L = keySpec.getPassword();
            System.out.print("My keySpec value is: ");
             for (int i=0; i<L.length;i++){
                System.out.print(L);
    //End Debug
    SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
    SecretKey secKey = keyFac.generateSecret(keySpec);
    return (secKey);

    OK, got to Eclipse and reproduced the problem using your code.
    Something about the way you were reading your password bugged me. I changed your code a bit to the following:import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.security.InvalidKeyException;
    import java.security.NoSuchAlgorithmException;
    import java.security.spec.InvalidKeySpecException;
    import javax.crypto.SecretKey;
    import javax.crypto.SecretKeyFactory;
    import javax.crypto.spec.PBEKeySpec;
    public class PBETest {
      static final int MAX_CHAR = 32;
      private char[] getPass() throws IOException {
        System.out.print("Input password ("+MAX_CHAR+" character max):");
        String s = new BufferedReader(new InputStreamReader(System.in)).readLine();
        char[] holder = s.toCharArray();
        int holdspot = (s.length()>MAX_CHAR?MAX_CHAR:s.length());
        //End Debug
        char[] pass = new char[holdspot];
        System.arraycopy(holder, 0, pass, 0, holdspot);
        //clear our holder array
        for (int i = 0; i < holder.length; i++) {
          holder[i] = 0;
        //Debug
        System.out.print("Pass: ");
        for (int i = 0; i < holdspot; i++) {
          System.out.print(pass);
    System.out.print("\n");
    System.out.print("Holder: ");
    for (int i = 0; i < holder.length; i++) {
    System.out.print(holder[i]);
    System.out.print("\n");
    //End Debug
    //Comment back in for final version, screen clear
    //System.out.flush();
    return (pass);
    private SecretKey createKey(PBEKeySpec keySpec)
    throws NoSuchAlgorithmException, InvalidKeyException,
    InvalidKeySpecException {
    //Debug
    System.out.println("createKey Entered");
    char[] L = keySpec.getPassword();
    System.out.print("My keySpec value is: ");
    for (int i = 0; i < L.length; i++) {
    System.out.print(L[i]);
    //End Debug
    SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
    SecretKey secKey = keyFac.generateSecret(keySpec);
    return (secKey);
    public static void main(String[] args) {
    try {
    PBETest ptest = new PBETest();
    char[] pwd = ptest.getPass();
    PBEKeySpec spec = new PBEKeySpec(pwd);
    SecretKey sk = ptest.createKey(spec);
    } catch (Exception e) {
    e.printStackTrace();
    }And now it works.
    I don't know exactly why your "one char at a time from System.in" bugged me, and I don't know exactly why it didn't work - but that was the problem.
    Grant

  • Simple Questions about ESB and ftp adapter.

    We have the following Business Scenario:
    We have a partner company that provide us a ftp server with some files. We need to transfer these files from this server to other server, we don't need to read the file's content, we just need transfer the files.
    We are planning to use ESB in order to implement this solution but we have the following questions:
    Is it possible use the ftp adapter in order to transfer the files?
    Is there any example available about (Schema is Opaque feature) on a ftp adapter?
    Thanks
    Ramiro Ortiz

    Thank you very much for your reply.
    . I am trying to construct a FTP ( get) adapter with which I would like to do a simple FTP transfer from /var/out directory server xxx.oms.com (say) to a directory /home/in on the server bos1.oms.com (say) could not figure out this in jdeveloper 10.1.3.3 ( do i need upgraded jdeveloper?). The esb server and control exists on server bos1.oms.com. While constructing the adapter in jdeveloper it asks for physical directory? Is this the directory where it will the read the file from? How do I specify if the directory exists on the different server.
    is it something like xxx.oms.com:/var/out
    Please let me know.

Maybe you are looking for

  • Special Characters issue in DEV and QAS

    Hi, I am uploading a file that has special characters (Japanese). In the DEV system the special character is converted to #. Which the business wants. In QAS system the special character is not converted and is as it is, which makes the business user

  • How can i find area under a closed curve

    I am having set of Y-values w.r.t X-values.When i am using numerical integration.vi to measure area, it is showing wrong answer.Is there any other vi to find the area under a closed curve.

  • JTextFields above column headers in JTable

    I am looking for a way to put a single row above (for filtering purposes) the table header in a JTable. Right now I am using JTextFields above my table for the filters, but as the columns are resized or moved so would the text fields have to be. So I

  • Downgrade kde 4.4 to kde 4.3

    I've just upgraded my system. Now I'm running kde 4.4. Everything is slower. After the system upgrade about 90 % of my ram (1G) is used constantly. Before the upgrade it rarely was more then 30 %.  So I want to get rid of kde 4.4 and downgrade is to

  • How to expose model node to other dc

    hi, now i want to expose model node to other dc. so i create data link from interface controller to model.in fact,the model node is exposed to other dc,but when i use it, i can not use it. please tell me the right way to do it.thanks