Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How to handle this particular Exception

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to handle this particular Exception

    Hi there!

    I call a function (called runFile) in my code that an external library provides me for running external scripts from file. I succesfully call any script I want to run, but the problem is that I don't know how to detect when the script I run is aborted by the user. I suppose it's done with the exception the API describes, but I don't know how to detect it. The description of the function in the library is the following:


    String runFile (String sScriptPath)

    Description: Run script from file(s)

    Parameters: sScriptPath file name which is either full path, wildcard mask or just base name, in this case the file issearched in current directory or using ucam.db key.

    Returns: String RUN_STATUS_OK if run is OK, otherwise returns message about issue encountered.

    Exceptions: AbortException if any problem encountered during script call


    And that's my code:


    RunFileReturn = runFile("C:\\macros\\ucammacros\\Blocs.vhs");		
    if(!isEqual(RunFileReturn,"OK"))
    {
    	promptStart();	
    		promptLabel("");
    		promptLabel("Hi ha hagut un error al repassar els pads als blocs.");
    		promptLabel("");
    		promptLabel("Aborta i recupera el circuit des de l'últim checkpoint.");
    	promptEnd();
    }


    The thing is that I correctly run "Blocs.vhs", but if I abort "Blocs.vhs" manually during it's execution, runFile still returns me "OK". Probably it only doesn't return "OK" in case it cannot find "Blocs.vhs" file, but I would like to know when the user aborts during "blocs.vhs".

    Could anyone tell me how can I do that? Is the exception described above what detects an abortion? Then, how can I use it?

    Thanks and sorry for my english!


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: How to handle this particular Exception

    Read up on try-catch clauses in java. Google it.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to handle this particular Exception

    Quote Originally Posted by Cornix View Post
    Read up on try-catch clauses in java. Google it.
    I tried that but I still don't detect abortion, that's my attempt with try-catch:

    try
    {
       //Protected code
       RunFileReturn = runFile("C:\\macros\\ucammacros\\Blocs.vhs",[{HabemusRear,bRepetError}]);		
       if(!isEqual(RunFileReturn,"OK"))
       {
    	promptStart();	
    		promptLabel("");
    		promptLabel("Hi ha hagut un error al repassar els pads als blocs.");
    		promptLabel("");
    		promptLabel("Aborta i recupera el circuit des de l'últim checkpoint.");
    	promptEnd();
       }
    }catch(AbortException e)
    {
       //Catch block
       promptStart();	
    	promptLabel("Exception found.");
       promptEnd();
        //do something
     
    }

    Could you tell me what's wrong?
    Last edited by jordileft; September 18th, 2014 at 01:58 AM.

  4. #4
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: How to handle this particular Exception

    No I cant. I dont know the library you are using and I dont know if the Exception is ever being thrown. Your syntax is fine.
    You could additionally add System.out.println statements in the catch block to make sure the exception is really not being thrown. It might be that your prompt class fails after an exception, but that is just wild guessing.

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to handle this particular Exception

    Quote Originally Posted by Cornix View Post
    No I cant. I dont know the library you are using and I dont know if the Exception is ever being thrown. Your syntax is fine.
    You could additionally add System.out.println statements in the catch block to make sure the exception is really not being thrown. It might be that your prompt class fails after an exception, but that is just wild guessing.
    I tried what you said and also tried with Throwable with no results. Looks like user abortion is not thrown, at least by the things I want to detect, at least knowing my syntax is fine I will be able to catch exceptions in the future.

    Thanks for your help!

  6. #6
    Junior Member
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to handle this particular Exception

    hello
    you are welcome
    with the help of long path tool, you have to handle.

    .................

Similar Threads

  1. How to handle string with characters
    By rkumar in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 17th, 2014, 02:34 AM
  2. How to handle Group Layout Manually
    By incredibleX in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 1st, 2013, 08:42 AM
  3. how to handle big numbers
    By veera in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 13th, 2013, 10:49 PM
  4. Try : handle an exception by yourself.
    By try in forum Member Introductions
    Replies: 1
    Last Post: July 12th, 2011, 10:37 AM
  5. how to handle many more exceptions
    By shailaja in forum Member Introductions
    Replies: 1
    Last Post: December 27th, 2010, 01:02 AM

Tags for this Thread