Weird thing with try-catch

Hey everyone, I have a problem compiling this .java
import java.io.*;
public class lector
    public static void main (String args[])
    public void lector()
        listapersonas listap = new listapersonas();
        listaconocidos listac = new listaconocidos();
        String linea, per, con;
        persona nuevapersona,actual,nuevoconocido;
        BufferedReader texto = new BufferedReader(new FileReader("conocidos.txt"));
        linea="";
        try {
        while ((linea=texto.readLine())!=null)
            per = linea.substring(0,linea.indexOf(','));
            con = linea.substring(linea.indexOf(','));
            nuevapersona = new persona(per);
            nuevoconocido = new persona(con);
            if (listap.existe(per)==false)
                nuevapersona.conocidos.agregar(nuevoconocido);
                listap.agregar(nuevapersona);
                linea=texto.readLine();
                continue;
            if (listap.existe(per)==true)
                if (listac.existe(con)==false)
                    listac.agregar(nuevoconocido);
                else
                    linea=texto.readLine();
                    continue;
            else
                linea=texto.readLine();
                continue;
        }  //while
        } //try
        catch (java.io.* e)
            System.out.print("Imposible leer el archivo");
        } //catch
    } //lector
} // classWell what it is supposed to do is read a string from a file and then transform and add them to a linked list.
The problem is that when I compile there is an error message called "<identifier> expected" and points to the catch block. Please help me

Nothing weird about it at all.
That's not the syntax of a catch block. What you've written there will only work in an import statement.
What you probably mean to catch is java.io.IOException.

Similar Messages

  • How to accept 2 strings in a class with try catch method..help!!

    the program below will accept two strings and compare str1 and str2 if equal. this program uses functions. can any one help me with this?
    import java.io.*;
    public class StrCompare {
         private BufferedReader takyoin = null;
         //private BufferedReader intakyo = null;
         * @param args
         public StrCompare(){
              takyoin = new BufferedReader(new InputStreamReader(System.in));
              //intakyo = new BufferedReader(new InputStreamReader(System.in));
         public String UserInput(){
         public static void main(String[] args) {
              // TODO Auto-generated method stub
    }

    What are you talking about? There is no such thing as "try-catch-methods", and there are no functions but methods.
    Strings by the way have their own means of comparision. Apart from that: do your own homework.

  • Surround With Try/Catch : comments issue

    hi
    Please consider this code:
         public static void main(String[] pArguments)
              FileInputStream vFileInputStream = new FileInputStream("someFile.txt");
              // some comments, e.g. several lines of commented code (that might be uncommented later)
         }It is possible to have JDeveloper "Surround With Try/Catch" this, but that results in this code:
         public static void main(String[] pArguments)
              FileInputStream vFileInputStream;
              // some comments, e.g. several lines of commented code (that might be uncommented later)
              try
                   vFileInputStream = new FileInputStream("someFile.txt");
              catch (FileNotFoundException e)
                   // TODO
         }Note that the declaration is before the comments and the try block starts after the comments.
    Is this intentional behaviour? I would prefer to leave the comments where they are, after the (modified) code.
    many thanks
    Jan Vervecken

    Thanks for your reply John.
    I tried the right-click "Surround With..." > "try-catch" approach you suggest, and I get this code:
         public static void main(String[] pArguments)
              try
                   FileInputStream vFileInputStream = new FileInputStream("someFile.txt");
              catch (FileNotFoundException e)
              // some comments, e.g. several lines of commented code (that might be uncommented later)
    }Indeed, the try-block starts before the comments.
    There is another difference with this approach, the declaration is not separated from the assignment.
    Next ... I'll try to remember which approach give which result. :)
    regards
    Jan

  • RAISERROR with Try/Catch does not exit after exception in catch block

    I am trying to propogate an error from within my proc out to the caller.
    In the attached example I have 2 sets of try catch blocks.
    I raiserror in the first
    catch the error and then raiserror again. (I expect to exit)
    I do not expect :
    to get to print 'post test'
    to get to second try block.
    but this does not exit, instead the code flows as per 2 runs.
    I do not understand the reason for the flows, as it seems counterintuitive to be raising an error but then still print following exceptions. I cannot seem to find any references that explains this behaviour.
     running tests together results
    print '-------------------------------------------------------'
    print 'test 15'
    exec test_raiseerror 15
    print '-------------------------------------------------------'
    print 'test 16'
    exec test_raiseerror 16
    print '-------------------------------------------------------'
    print 'test 17'
    exec test_raiseerror 17
    print '-------------------------------------------------------'
    print 'test 18'
    exec test_raiseerror 18
    print '-------------------------------------------------------'
    'RESULTS'
    test 15
    error number provided: 15
    Msg 50000, Level 15, State 1, Procedure test_raiseerror, Line 21
    name hello 15
    post test
    15
    Msg 50000, Level 15, State 1, Procedure test_raiseerror, Line 37
    name hello 2 15
    post test2
    test 16
    error number provided: 16
    Msg 50000, Level 16, State 1, Procedure test_raiseerror, Line 21
    name hello 16
    post test
    16
    Msg 50000, Level 16, State 1, Procedure test_raiseerror, Line 37
    name hello 2 16
    post test2
    test 17
    error number provided: 17
    post test
    17
    post test2
    test 18
    error number provided: 18
    post test
    18
    post test2
    Msg 50000, Level 17, State 1, Procedure test_raiseerror, Line 21
    name hello 17
    Msg 50000, Level 17, State 1, Procedure test_raiseerror, Line 37
    name hello 2 17
    Msg 50000, Level 18, State 1, Procedure test_raiseerror, Line 21
    name hello 18
    Msg 50000, Level 18, State 1, Procedure test_raiseerror, Line 37
    name hello 2 18
    run tests seperately
    exec test_raiseerror 15
    error number provided: 15
    RESULTS 15
    Msg 50000, Level 15, State 1, Procedure test_raiseerror, Line 21
    name hello 15
    post test
    15
    Msg 50000, Level 15, State 1, Procedure test_raiseerror, Line 37
    name hello 2 15
    post test2
    exec test_raiseerror 16
    RESULTS 16
    error number provided: 16
    Msg 50000, Level 16, State 1, Procedure test_raiseerror, Line 21
    name hello 16
    post test
    16
    Msg 50000, Level 16, State 1, Procedure test_raiseerror, Line 37
    name hello 2 16
    post test2
    exec test_raiseerror 17
    RESULTS 17
    error number provided: 17
    post test
    17
    post test2
    Msg 50000, Level 17, State 1, Procedure test_raiseerror, Line 21
    name hello 17
    Msg 50000, Level 17, State 1, Procedure test_raiseerror, Line 37
    name hello 2 17
    exec test_raiseerror 18
    RESULTS 18
    error number provided: 18
    post test
    18
    post test2
    Msg 50000, Level 18, State 1, Procedure test_raiseerror, Line 21
    name hello 18
    Msg 50000, Level 18, State 1, Procedure test_raiseerror, Line 37
    name hello 2 18
     CODEBLOCK:
    if object_id('test_raiseerror','P') is not null
    drop proc test_raiseerror
    go
    create proc test_raiseerror(@id as int) as
    begin
    begin try
    declare @name varchar(20)
    select @name = 'hello'
    raiserror('name %s %d',@id,1,@name,@id)
    print 'next'
    end try
    begin catch
    declare @errormessage nvarchar(4000)
    declare @errornum int
    select @errormessage = error_message()
    , @errornum = error_severity()
    print 'error number provided: ' + convert(varchar(2),@errornum)
    raiserror(@errormessage, @errornum,1)
    print 'post test'
    end catch
    begin try
    select @name = 'hello 2'
    raiserror('name %s %d', @id,1,@name, @id)
    end try
    begin catch
    select @errormessage = error_message()
    , @errornum = error_severity()
    print @errornum
    raiserror(@errormessage, @errornum,1)
    print 'post test2'
    end catch
    end
    go
    sqlserver 2008 & 2008 R2

    There is a Connect that describes a similiar complaint.  But basically a raiserror inside a catch block does not terminate the procedure, it will continue with any additional code in the CATCH and FINALLY unless it hits a return statement.
    http://connect.microsoft.com/SQLServer/feedback/details/275308/have-raiserror-work-with-xact-abort

  • Please help with try/catch

    Hello, I'm writing a program and I got surprised with the following. I've got the following try/catch block:
    try {
    String param = config.getConfigValue("db2.driver");
    if (param == null)
    // parameter not defined.
    throw new Exception("Parameter 'db2.driver' missing!");
    else
    Class.forName(param);
    catch (SQLException sqlEx) {
    // do something
    catch (Exception e) {
    System.out.println("*** ERROR loading driver..."); (1)
    finally {
    releaseDB2Resources();
    I know the program flow goes through the finally block, but it doesn't print the message (1). Why is that? I don't understand it. What am I doing wrong?
    Thanks in advance.

    A finally block always gets executed, so that's why the println always works there. The only reason why the println in the catch wouldn't work is if that exception wasn't thrown. If a config value is not there, it might be the null string "" instead of null. Try this:
    if (param.equals(""))
    throw new Exception("blah");
    You could also try:
    if (true)
    throw new Exception("blah");
    to make sure that the exception is caught where you think it should be.

  • Exception handling with try/catch in acrobat

    Hi
    I have a problem using a try/catch block in my acrobat document-script. Try to enter the following into the debugger-console:
    try{nonexistentFunction();}catch(e){console.println('\nacrobat can't catch')}
    and run it. The output will be:
    nonexistentFunction is not defined
    1:Console:Exec
    acrobat can't catch
    true
    The whole point of a rty/catch block is for the application  NOT to throw an exception, but instead execute the catch-part of the  statement. However, acrobat does both: It throws an exception AND  executes the catch-block.
    Is there another way to suppress the exception, or to make the try/catch-block work as it's supposed to?

    > Also Adobe provides for free the JS or compiled file for Acrobat Reader to support the JS console.
    Where is that file located ? How to install it or where to place it ?
    What is the method referred by try67 on his site where he sells a product ?
    Is that the same as the compiled file you refer to ? or did he sell his solution to adobe ?
    It is helpful if people can get an idea of the nature of choices available and make informed decisions, than a cloak and dagger approach.
    For some jobs that we have, I have been very frustrated by a consultant who wont even give basic info for transparent billing despite all assurances for privacy, as a result we are forced to do the job ourselves.
    Dying Vet

  • Weird things with mini

    My mini started acting up about a week and a half ago. First it got disconnected from my comupter without being ejected and all the songs got deleted. The next time I tried to turn it on, I got the sad ipod picture followed by a battery picture. The sad ipod is still there but the battery picture is gone now. Plus, when I try to turn it on it starts making this weird clicking noise. I've tried to manually do the disc thing or whatever it's called, and it didn't work. Normally, I would just drop it off to a repair shop, but the nearest one is in another city. Any suggestions???
    P.s. a week before all this it locked up one day. came back on after the batter drained.
    ipod mini    

    I'll cut to the chase: the clicking hard-drive noise means your disk is done. You can either replace the CF microdrive, or buy a new iPod (assuming you're out of warranty). Since I like the Mini design, I decided to do the former; checkout the article I wrote about my experience.
    http://www.audioholics.com/techtips/setup/loudspeakers/iPodMiniUpgrade.php

  • Weird thing with charger

    So I was letting my MBP cycle through with its battery as I always do.  I was down to like 4 percent, and I got the message to plug in my charger.  When I did, nothing happened.  There was no red light, just a dim green one, and it said my computer wasn't charging and that it was running on the magsafe power.  I closed my computer and let the battery run out.  When I did, I plugged the charger back in and it started charging.  Then when I unplugged it, and plugged it back in, nothing happened.  Any one know what's up with this?

    Hold the CONTROL COMMAND POWER keys for several seconds.
    Try a SMC reset:
    http://support.apple.com/kb/ht3964
    Try a PRAM rest:
    http://support.apple.com/kb/ht1379
    Ciao.

  • Weird Thing With Exporting As Quicktime Movie

    Ok, so this has been happening for months now, but I didn't really think anything of it until now. Whenever I export a movie as a Quicktime Movie, it exports it as 2 files, the regular movie file, and the same file with "-av1" behind it. The second part has to be there in order for it to play. What's stranger is that when I put them into a folder, the movie no longer plays properly. What is up with this?

    I have just experienced the -av1 phenomena for the first time.
    I have been exporting to QT movies regularly using the same internal and external drives for months - no changes, no incorrect formatting. I have used those exported movies to create One-Step DVDs in iDVD for display and distribution. This -av1 file thing is keeping me from doing that.
    The only diff with this project (and, in fact, it's a new Sequence in a Project that has successfully been exported (without the companion file)) is that this sequence had .aiff music files some of which were from iTunes (downloaded/protected).
    I thought that might be the problem, so I created mp3s (by burning to disk and re-importing) and replaced the aiff's in the timeline - it still insisted on creating -av1 files with the QT Movie.
    Help would be appreciated.
    Thanks.
    MacBook Pro Mac OS X (10.4.8)
    MacBook Pro   Mac OS X (10.4.8)  

  • Weird things with my ipod

    I've been having a lot of problems with my iPOD. Whenever I reset it, because sometimes it freezes, it stays on the Apple logo for a little bit. Then a dead ipod image appears and then the apple support web site comes up. I'm not really sure what to do. I've tried resetting it a lot and nothing seems to work.

    Try this Hard Reset, (it wont delete any song or data on your iPod), from time to time to clear the cache.
    After charging till full charge, at least 2 hours (preferably 4 hours)
    Toggle the Hold switch, make sure you dont see the red mark when you do the  next step
    Reset the iPod -> Press Menu and Center button simultaneously for about 10 secs till the Apple Logo comes ON
    Then release the buttons
    Select your preferred language.
    Here is the Apple support Article on the 5Rs
    http://www.apple.com/support/ipod/five_rs/classic/
    If it doesn't work, bring it in to Apple Store for the Genius to have a look.
    Good Luck!

  • Need help with try catch

    i have a catch block as follows
    catch (FileNotFoundException fnfe) {
                   System.out.println ("Library of Leng could not find a needed file.");
                   System.out.println (fnfe.printStackTrace());
                   JOptionPane.showMessageDialog (desktop, "File not found.", "ERROR", JOptionPane.WARNING_MESSAGE);
    but when i compile it says that void is not allowed and highlights the line:
    System.out.println (fnfe.printStackTrace());
    but according to the api this is a valid method.
    am i not reading this right or is java just fscked up?

    "am i not reading this right or is java just fscked up? "
    The problem is ALWAYS between the chair and the monitor. There are way to many coders working with and on java for such a mistake to (still) be present.
    In this case a "RTFM" was a proper response, because the javadocs clearly state that printStackTrace() returns void.

  • K9A2 Platiunum - 'weird' things with Network and USB are happening...

    Hi All,
    My System specs are:
    MSI K9A2 Platinum MB
    OCZ Technology 2x2GB 240DIMM PC2-6400 Gold running at 2.2V
    AMD Phenom 9500
    2 x Samsung SATA DVD Writer SH-203B/BEBN
    GeForce 8800GTX 768MB PCIE DVI
    Coolermaster Cosmos case
    Seagate 320GB SATA2 HDD ST3320620AS
    OCZ 1010 GameXstream PSU
    OS: Vista Home Premium 64
    It was quite a task getting this machine working in the first place (see my previous threads) but I have a residual issue here that I would like to put to you and see if anyone has any ideas:
    1) I noted that there seems to be something 'wrong' with my Network connection as a) my internet was very unstable on this machine ("no cable plugged in / no connection" messages) from time to time. No pattern detectable, seems to have "gone away" now; and b) my Belkin F5D7235-4 router gives me an 'amber' status light, instead of green, for the connection to the above machine. I changed the port at the router and also changed the network cable to a new one - the status light remains on amber.
    Interestingly, the status light changes to amber only once the start-up process of the PC has progressed, it is 'green' when the PC is switched off.
    2) A function of the above problem seems to be that I cannot get a network with my 2nd machine (XP SP2 based) going. I applied the patch that has to be applied when XP SP2 and Vista machines are in the same network. The two PC's saw each other once - and then never again.
    3) Had a friend over and wanted to transfer 160GB from my external WD 1TB drive (connected through Firewire 800 to the K9A2 based machine) to his laptop via USB2.0, using my Vista / MSI K9A2 Platinum based machine (specs above). After minutes of calculating the estimated time remaining it came back to me with around "5 days 7 hours remaining". Cancelled and then used my XP SP2 based machine to perform the same task and I got "1 hour, 10 minutes remaining" and it actually got done done in that time.
    Summary: I am asking myself if I have something set-up just completely the wrong way in my MSI K9A2 Plat based machine on the BIOS level regarding the on-board network card. If yes, what could that be? But then, on top, why is this really slow USB2.0 thing happening??
    I am grateful for any ideas as I feel that I have not been able to get the top performance out of my PC yet.
    Thanks to all of you for some thoughts...
    Ciliax

    Upgrade? Fresh installation on a newly formatted disk is to prefer.
    This is little beside the point, but when installing Windows I use as little hardware as possible. It is much easier to add things afterwards than troubleshooting a complex coordination of things.

  • Album art doing weird things with iTunes 7.3.1.3

    About a week after I got this version, all my music got deleted somehow. I've added it all back, but album art is screwy. Sometimes it only shows a black square where the art should be. Other times it won't change the art to what I want it to be. These things happen regardless of whether I change many songs at once or one at a time. Is there a patch or something? I don't want to restore the iPod again...it takes way too long to rename all my songs and put them in specific playlists!!

    Hi blob2,
    Although it may not be the solution to your problem, there's been a new version of iTunes that was released a few days ago, which may provide some sort of help with this issue for you.
    The latest version is 7.3.2.6, and can be downloaded from Apple's website, here:
    Download iTunes - 7.3.2.6
    By the way, does this happen when you're trying to view the album art on your iPod, or does this just happen with your iTunes library?
    -Kylene

  • Doing weird things with dataTipFormatFunction

    OK, so here's my little problem:
    I need to have a slider that spans a significant range of
    values. The range (if we're talking units of time) goes from one
    year all the way down to one second, with the difference between,
    say, five and ten seconds being about as significant as the
    difference between five and ten months.
    "Aha!" I cried to myself. "That just means that I need to use
    some of that fancy-dancy mathematics stuff that I learned in that
    big brick building I went to once!"
    And indeed, that's what I did: I put together a new component
    by just inheriting from VSlider and tacking on some methods to
    process slider.value as the input to a logarithmic scale. It's
    pretty cool, too. All I do is bind to my slider.time property and
    boom! I've got a slider that goes from a year to a second, with the
    user being able to make fine-grained adjustments easily.
    The only snafu popped up (quite literally) with the data tip,
    which still showed slider.value. Kinda broke the illusion. No
    problem: I just replaced dataTipFormatFunction with a function that
    discarded the old slider.value-based string and returned a new one
    based on my slider.time property. It even formatted it nicely,
    switching units from seconds to minutes to hours to days to months.
    But there's one last niggling problem. If I'm dragging the
    slider along with the data tip showing and a neighboring text field
    bound to slider.time, I get two different outputs. Dragging up the
    scale, for example, my bound text field will say six seconds, while
    the data tip still shows five. Releasing the thumb and clicking on
    it again at that point will show the data tip at six seconds,
    leading me to believe the following:
    1) The string with which dataTipFormatFunction() is called is
    based on the change event, *not* the slider.value, and
    2) dataTipFormatFunction() is getting called *before* the
    slider.value is assigned the new value.
    So first, is that a fair conclusion? Since my custom data tip
    function discards the old string and builds the new one based on a
    function that accesses slider.value, it seems like a reasonable
    guess.
    Second, anybody have any suggestions? I see two alternatives
    right now: disable data tips, or extract the number from the
    original string and pass it into a method that will re-scale it.
    The second option is just kinda kludgy, so I'll probably just kill
    the data tips, but I do like having the pop-up feedback available
    while the user is making fine-grained adjustments.
    Any other approaches? Am I missing something? Should I have
    gone into podiatry like my mother wanted?

    Hi blob2,
    Although it may not be the solution to your problem, there's been a new version of iTunes that was released a few days ago, which may provide some sort of help with this issue for you.
    The latest version is 7.3.2.6, and can be downloaded from Apple's website, here:
    Download iTunes - 7.3.2.6
    By the way, does this happen when you're trying to view the album art on your iPod, or does this just happen with your iTunes library?
    -Kylene

  • Weird thing with Follow up Transaction

    Hi All
    I am having a problem with a follow up transaction, in that the texts for the follow up can not be maintained until I do a save.
    I have enhanced component ICCMP_BTSHEAD.   
    I placed a button on the view called "create action".  When this is clicked I create a follow up transaction and then navigate to the follow up transaction.
    My problem is with the Notes view on this screen.
    The drop down is populated with the correct note types.  There are two notes relating to my follow.  If I enter a text in the first note, then select the second note and enter text and then select the first note again, the text from the first note is gone and I have to enter it again.
    Anyone come accross this issue?
    Any suggestions as to how to fix it ?
    Is this because I am navigating to the same component when I create the follow up.
    Any help would be great.

    Hi Darren ,
    Have you checked the text type entries in SPRO .
    Please specify how you are defining the "Define Text Determination Procedure" in SPRO .
    Goto SPRO->Customer Relationship Management->Basic Functions->Text Management->Define Text Determination Procedure
    Regards
    Manish

Maybe you are looking for