BufferedWriter try catch Scoping problem

I developed a quick and dirty application to search through a file system for files that contain certain patterns in their names, and it works fine. My problem is I want to use a BufferedWriter to write the results out to a new text file, and a buffered writer must be enclosed in a try catch statement because of a possible IOException. Now the writer is out of scope of the method that needs to call it, and if I put it in the method a new writer and hence a new file will be created each time through. I am sure this is just a design flaw on my part but I have hit this problem before, I was wondering what is a way around this, so the writer can be instantiated, the method that will do that actual writing to the file will be called until the iteration is done, and then the program will exit.
Here is my code, there are some unused variables and objects in there, namely I am not using the BufferedWriter at the moment and was just cutting and pasting from the console:
Thanks!
import java.io.*;
import java.util.*;
public class NextAttempt {
     static List<File> filelist = new ArrayList<File>();
     static PrintStream out = new PrintStream(System.out);
     static File f;
     public static void getWriter() {
          try {
               BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\FILE.txt"));
                    for(File f: filelist)
                         writer.append(f.getAbsolutePath());
          catch (Exception e) {}
     public static List<File> browse(File BASE) {
          File[] temp=BASE.listFiles();
               for (int i=0;i<temp.length;i++) {
                    if(temp.getAbsolutePath().contains(File.separator+"PATTERN")&&temp[i].getName().contains(".ext") {     
                         out.println(temp[i].getAbsolutePath());
                         //filelist.add(temp[i]);
                    else if (temp[i].isDirectory()) {
                              BASE=temp[i];
                              rec(BASE);
                    else {
                         BASE=new File("PATH");
          return filelist;
     public static void rec(File BASE) {
          browse(BASE);
     public static void main(String[] args) {
          browse(new File("PATH"));
          out.println("Complete");

Also you can keep passing the file lists up to the callers, so the initial invocation of browse() will return a list of all the files. When you recurse (which you're doing now, apparently), you can append the return value of the recursive call to the caller's own list of files.
Then just print the whole list when you're done.
Another thing you might want to think about... you could use the logging framework to list the files as log entries. That may or may not be useful. The advantage is that the logging code already deals with some of these issues; the disadvantage is that producing a formatted log might result in a format you can't use, or tweaking the format might be more trouble than doing something else.

Similar Messages

  • Try-catch statment problems

    I'm trying to understand the try-catch statements. I'm trying to verify that a number entered is only within a range of 1-3, otherwise get the input again. But I'm not grasping the try-catch statements very well, and my code isn't working correctly. It seems to just by pass the catch statement completely. Any idea on what I'm doing wrong with this?
              try {
                   System.out.println("Enter the test number");
                   testNumb = scan.nextInt();
                   if(testNumb < 1 && testNumb > 3){
                        throw new Exception("Test Number not valid");
              catch(Exception e){
                   System.out.println(e + "please enter a valid test (number between 1-3)\nEnter the test number");
                   testNumb = scan.nextInt();
              }

    I don't understand why its still crashing, when it should catch the InputMismatchException, and run the code INSIDE of the exception, which asks the user to enter the input again. It does ask the USER, but it still just crashes.
    I've changed the method around so it is more like what post #8 said. But its still crashing, I'm not sure if its something specific I dont understand, or what.
         public static int studentTest(){
              Scanner scan = new Scanner(System.in);
              boolean acceptable = false;
                   while(!acceptable){
                        try {
                             System.out.println("Enter the test number");
                             testNumb = scan.nextInt();
                        catch(InputMismatchException ioe){
                             System.out.println("Test Number not valid, please enter a valid test (number between 1-3)\nEnter the test number");
                             testNumb = scan.nextInt();
                        if(testNumb < 1 || testNumb > 3){
                             System.out.println("Test Number not valid, please enter a valid test (number between 1-3)\nEnter the test number");
                             testNumb = scan.nextInt();
                        } else {
                             acceptable = true;
                   return testNumb;
         }

  • Problem with a Try/catch exception

    Hello everyone here on the forums. I'm brand new to Java and have a bit of a problem with a try catch statement I'm making. In the following code if a user enters a non-integer number the program will display "Sorry, incompatible data." Problem is it gets caught in a loop and continues to display "Sorry, incompatible data." My aim with the try catch was if the user is not quite smart enough to understand quadratic programs don't use symbols and characters it would state it isn't correct and continue running the program.
    Heres my code thus far:
    package finishedquadraticprogram;
    import java.util.*;
    * @author Matt
    public class quad {
         * @param args the command line arguments
        public static void main(String[] args) {
            boolean verification = true;
            double a, b, c, root1, root2, discriminant;
            Scanner keyInput = new Scanner(System.in);
            while ( verification)
            try
            System.out.println("a: ");
            a = keyInput.nextDouble();
            System.out.println("b: ");
            b = keyInput.nextDouble();
            System.out.println("c: ");
            c = keyInput.nextDouble();
            discriminant = Math.sqrt(b * b - 4 * a * c);
            root1 = (-b + discriminant) / 2 * a;
            root2 = (-b - discriminant) / 2 * a;
            verification = false;
            System.out.println("Root 1 = " +root1+ "\nRoot 2 = " +root2);
            } //try
            catch  (InputMismatchException iMe)
              System.out.println( "Sorry. incompatible data." );  
    }I'm pretty sure the problem is something to do with the keyboard buffer, but I'm not sure what I need to do to either reset it or clear it, whichever one works. (Oh, and how would I go about making the program use complex numbers? I realize Java can't use complex numbers and will just display NaN ... any ideas how to make this work?)
    Thanks a lot for all of your help guys, it's appreciated.

    this is better:
    package finishedquadraticprogram;
    import java.util.*;
    /** @author Matt */
    public class quad
       private static final double TOLERANCE = 1.0e-9;
       /** @param args the command line arguments */
       public static void main(String[] args)
          boolean verification = true;
          double a, b, c, root1, root2, discriminant;
          Scanner keyInput = new Scanner(System.in);
          while (verification)
             try
                System.out.println("a: ");
                a = keyInput.nextDouble();
                System.out.println("b: ");
                b = keyInput.nextDouble();
                System.out.println("c: ");
                c = keyInput.nextDouble();
                discriminant = Math.sqrt(b * b - 4 * a * c);
                if (Math.abs(a) < TOLERANCE)
                   root1 = 0.0;
                   root2 = -c/b;
                else
                   root1 = (-b + discriminant) / (2 * a);
                   root2 = (-b - discriminant) / (2 * a);
                verification = false;
                System.out.println("Root 1 = " + root1 + "\nRoot 2 = " + root2);
             } //try
             catch (InputMismatchException iMe)
                System.out.println("Sorry. incompatible data.");
                keyInput.next();
    }

  • Try  Catch problem CS6

    All my try catch scripts don't work on CS6
    $.strict = false;
    function myGetScriptPath() {
    try{
    return app.activeScript;
    catch(myError){
    return File(myError.fileName);
    myGetScriptPath()
    Can anyone tell me the problem?
    Thanks
    Trevor

    Thanks for trying Pickory,
    I have Windows 7, with both indesign CS5 and creative cloud CS6 installed
    After experimenting I found that the script works fine on the machine with just CS5 on it.
    But on the one that has both doesn't work when called from either version of the ESTK but does from either version of indesign.
    When I try run the script from the CS5 ESTK It automatically opens and runs from the CS6 ESTK.
    I am not keen on uninstalling the CS5 ESTK as I don't know how long I'll keep creative cloud.
    Bellow is a alternative try catch script because the above one will not invoke an error if run from indesign so it won't call the catch.
    cs = app.activeDocument.characterStyles.item("myCharacterStyleName");
    try {alert ("Try $.strict = " +$.strict); myCharacterStyle.name}
    catch (myError) { alert ("Catch $.strict = " +$.strict + "\r" + myError)}
    I'm quite desperate for an answer.

  • Try catch problem in a while loop

    I have computerGuess set to -1 and that starts the while loop.
    but I need to catch exceptions that the user doesnt enter a string or anything other than a number between 1 and 1000.
    but computerGuess is an int so that the while loop will start and I wanted to reset computerGuess from the user input using nextInt().
    The problem is if I want to catch exceptions I have to take a string and parse it.
    import java.util.Scanner;
    public class Game {
         //initiate variables
         String computerStart = "yes";
         String correct = "correct";
         String playerStart = "no";
         int computerGuess = 500;
    public void Start()
         //setup scanner
         Scanner input = new Scanner(System.in);
         int number = (int)(Math.random()*1001);
         System.out.println(welcome());
         String firstAnswer = input.nextLine();
         if(firstAnswer.equalsIgnoreCase(computerStart)== true)
              System.out.println(computerGuess());
              //while (userAnswer.equalsIgnoreCase(correct) == false){
                   System.out.println();
         if(firstAnswer.equalsIgnoreCase(playerStart) == true)
              long startTime = System.currentTimeMillis();
              int currentGuess = -1;
              while (currentGuess != number){
              System.out.println(playerGuess());
              String guess = input.next();
              //currentGuess = Integer.parseInt(guess);
              if (currentGuess < number)
                   System.out.println("too low");
              if (currentGuess > number)
                   System.out.println("too high");
              if (currentGuess == number)
                   long endTime = System.currentTimeMillis();
                   System.out.println("Well done, the number is " + number);
              int i = -1;
              try {
                i = Integer.parseInt(guess);
                   } catch (NumberFormatException nfe) {
                        //System.out.println("Incorrect input, please try again.");
              if ( i < 0 || i > 1000 ) {
                   System.out.println("Incorrect input, please try again.");
         private String computerGuess()
               String comGuess = ("The computer will guess your number.\n" +
                        "Please enter \"too high\", \"too low\" or \"correct\" accordingly.");
               return comGuess;
         private String welcome()
              String gameWelcome = "Welcome to the guessing game \n" +
                                        "The objective is to guess a number between 1 and 1000.\n" +
                                        "You can guess the computer's number or it can guess your's.\n" +
                                        "You may enter \"quit\" at any time to exit.\n" +
                                        "Would you like the computer to do the guessing?";
              return gameWelcome;
         private String playerGuess()
              String playerWillGuess = "Guess a number between 1 and 1000.";
              return playerWillGuess;
    }The catch works , but because computerGuess is int -1 so that the while loop will run, I cannot use the input to change computerGuess because it is a string.

    the i was a mistake. and i commented on the other code, because it wasnt working at that moment. I need help understanding the try catch method.
    I want to catch any input that isn't an integer , and I would also like to catch any input that isn't a string at other parts of my program.

  • Return statement and Try Catch problem

    Hi!!
    I've got the next code:
    public ResultSet DBSelectTeam(String query) {
    try {
    Statement s = con.createStatement();
    ResultSet rs = s.executeQuery(query);
    return rs;
    } catch (Exception err) {
    JOptionPane.showMessageDialog(null, "ERROR: " + err);
    But I need a return statement in the catch-block, but I don't know what's the best option.
    Help...
    Many thanks.

    The error message is: "missing return statement", Yes, I know.
    You have to either return from the catch statement, or throw from the catch statement, or return or throw after the catch statement.
    The only ways your method is allowed to complete is by returning a value or throwing an exception. As it stands, if an exception is thrown, you catch it, but then you don't throw anything and you don't return a value.
    So, like I said: What would you return from within or after catch? There's no good value to return. The only remotely reasonable choice would be null, but that sucks because now the caller has to explicitly check for it.
    So we conclude that catch shouldn't return anything. So catch must throw something. But what? You could wrap the SQLE in your own exception, but since the caller is dealing with JDBC constructs anyway (he has to handle the RS and close it and the Statement), there's no point in abstracting JDBC away. Plus he has to deal with SQLE anyway in his use of the RS and Statement. So you might as well just throw SQLE.
    So since you're going to just throw SQLE anyway, just get rid of the try/catch altogether and declare your method throws SQLException

  • Plugin and try/catch problem

    I have a plug-in that was working perfectly until I added an FileOutputStream and its corresponding try/catch block. Now when I try to run my plugin, the popup menu come up corrctly but when I click to run my code it tells me the operation is not available. If I delete those three line it works fine again.
    Instead or try/catch I could do run() throws XYZException, but that gives an error. Any ideas how I can get this fixed? Thanks

    turns out that was not really what was causing the error. I was using the iText library, and I had added it to the classpath of the plugin but I didnt add it to the runtime classpath, so my 'new' eclipse windows was not working properly. Thanks anyways

  • A try catch problem....

    public class trycatch{
    public static void main(String[] adsf){
    int i;
    try{i = 5;}
    catch(Exception e){}
    System.out.println("hello"+i);
    }at compile time, the compiler says i might not have been initialised, but why?
    I have done it in try catch block.

    do you people have any better idea rather than put
    all the codes in one try catch block?Yes.
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.io.InputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.FileNotFoundException;
    public class Test{
           public static void main(String[] param){
                  if(param.length!=4)
                  System.out.println("please provide 4 attributes: protocol, host, port, and file");
                  URL resource = null;
                  try{resource = new URL(param[0], param[1], Integer.parseInt(param[2]), param[3]);}
                  catch(MalformedURLException murle){System.out.println("an murle occurs");return;}
                  InputStream openResource = null;
                  try{openResource = resource.openStream();}
                  catch(IOException ioe){System.out.println("an ioe occurs");return;}
                  FileOutputStream toFile = null;
                  try{toFile = new FileOutputStream(param[3]);}
                  catch(FileNotFoundException fnfe){System.out.println("an fnfe occurs");return;}
                  try{
                  for(int i = openResource.read(); i!=-1; i = openResource.read())
                  toFile.write(i);
                  catch(IOException ioe){System.out.println("an ioe occurs");}
    }Notice the initialization. That will now at least compile. And before you get your knickers in a knot the return statements are there for terminiating execution of the method (in this case program) when an error occurs.

  • Can't find class because of try catch block ?!

    Hello,
    I'm using the JNI to use a java library from my c++ code.
    JNI can't find the "Comverse10" class below, but when i put the try catch block in createMessage in comment, FindClass succeeds ?!
    Unfortunatly i need the code inside the try block ;-)
    I tried a few things, but none of them worked:
    - let createMessage throw the exception (public void createMessage throws ElementAlreadyExistsException ), so there isn't a try catch block in createMessage => result: the same
    - make a "wrapper" class Comverse that has a Comverse10 object as attribute and just calls the corresponding Comverse10.function. Result: Comvers could be found, but not constructed (NewObject failed).
    Can someone tell me what is going on ?!
    Thank you,
    Pieter.
    //Comverse10 class
    public class Comverse10 {
    MultimediaMessage message;
    /** Creates a new instance of Comverse10 */
    public Comverse10() {
    public void createMessage() {
    TextMediaElement text1 = new TextMediaElement("Pieter");
    text1.setColor(Color.blue);
    SimpleSlide slide1 = new SimpleSlide();
    //if i put this try catch block in comment, it works ?!
    try{
    slide1.add(text1);
    catch(com.comverse.mms.mmspade.api.ElementAlreadyExistsException e){}
    MessageContent content = new MessageContent();
    content.addSlide(slide1);
    this.message = new MultimediaMessage();
    message.setContent(content);
    message.setSubject("Mijn subjectje");
    for those of you who are intersted: here's my C++ code:
    //creation of JVM
    HRESULT Java::CreateJavaVMdll()
         HRESULT HRv = S_OK;
    char classpath[1024];
         jint res;
         if(blog)     this->oDebugLog->Printf("CreateJavaVMdll()");
         strcpy(classpath,"-Djava.class.path="); /*This tells jvm that it is getting the class path*/
         strcat(classpath,getenv("PATH"));
         strcat(classpath,";D:\\Projects\\RingRing\\MMSComposer;C:\\Progra~1\\j2sdk1~1.1_0\\lib");     //;C:\\Comverse\\MMS_SDK\\SDK\\lib\\mail.jar;C:\\Comverse\\MMS_SDK\\SDK\\lib\\activation.jar;C:\\Comverse\\MMS_SDK\\SDK\\lib\\mmspade.jar
         //------Set Options for virtual machine
         options[0].optionString = "-Djava.compiler=NONE"; //JIT compiler
         options[1].optionString = classpath;                                        //CLASSPATH
         //------Set argument structure components
         vm_args.options = options;
         vm_args.nOptions = 2;
         vm_args.ignoreUnrecognized = JNI_TRUE;
         vm_args.version = JNI_VERSION_1_4;
         /* Win32 version */
         HINSTANCE hVM = LoadLibrary("C:\\Program Files\\j2sdk1.4.1_01\\jre\\bin\\client\\jvm.dll");
         if (hVM == NULL){
              if(blog) oDebugLog->Printf("Can't load jvm.dll");
              return E_FAIL;
         if(blog) oDebugLog->Printf("jvm.dll loaded\n");
         LPFNDLLFUNC1 func = (LPFNDLLFUNC1)GetProcAddress(hVM, "JNI_CreateJavaVM");
         if(!func){
              if(blog)     oDebugLog->Printf("Can't get ProcAddress of JNI_CreateJavaVM");
              FreeLibrary(hVM);     hVM = NULL;
              return E_FAIL;
         if(blog)     oDebugLog->Printf("ProcAddress found");
         res = func(&jvm,(void**)&env,&vm_args);
         if (res < 0) {
    if(blog)     oDebugLog->Printf("Can't create JVM with JNI_CreateJavaVM %d\n",res);
    return E_FAIL;
         if(blog)     oDebugLog->Printf("JVM created");
         return HRv;
    //finding Comverse10 class:
    HRESULT CALLAS MMSComposer::InitializeJNI(void)
         HRESULT HRv=E_FAIL;
         DWORD T=0;
         try
              if(blog)     oDebugLog->Printf("\nInitializeJNI()");
              bJVM = FALSE;
              jni = new Java(oDebugLog);
              if(jni->CreateJavaVMdll()!=S_OK){
                   if(blog)     oDebugLog->Printf("CreateJavaVMdll() failed");     
                   return HRv;
              jclass jcls = jni->env->FindClass("Comverse10");
              if (jcls == 0) {
    if(blog)     oDebugLog->Printf("Can't find Comverse10 class");
                   jclass jcls2 = jni->env->FindClass("test");
                   if (jcls2 == 0) {
                        if(blog)     oDebugLog->Printf("Can't find test class");
                        return HRv;
                   if(blog)     oDebugLog->Printf("test class found %08x",jcls2);
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10 class found %08x",jcls);
              jmethodID mid = jni->env->GetMethodID(jcls , "<init>", "()V");
              if (mid == 0) {
                   if(blog)     oDebugLog->Printf("Can't find Comverse10() constructor");
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10() constructor found");
              jobject jobj = jni->env->NewObject(jcls,mid);
              if(jobj==0)
                   if(blog)     oDebugLog->Printf("Can't construct a Comverse10 object");
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10 object constucted");
              //Create Global reference, so java garbage collector won't delete it
              jni->jobj_comv = jni->env->NewGlobalRef(jobj);
              if(jni->jobj_comv==0)
                   if(blog)     oDebugLog->Printf("Can't create global reference to Comverse10 object");
    return HRv;
              if(blog)     oDebugLog->Printf("global reference to Comverse10 object %08x created",jni->jobj_comv);
              bJVM=TRUE;
              HRv=S_OK;
         }     catch( IDB * bgError ) { throw bgError->ErrorTrace("InitializeJNI::~InitializeJNI",HRv, 0, T); }
              catch(...) { throw IDB::NewErrorTrace("InitializeJNI::~InitializeJNI",HRv, 0, T ); }
              return HRv;

    >
    I would guess that the real problem is that that the
    exception you are catching is not in the class path
    that you are defining.Thanks jschell, that was indeed the case.
    I don't have the docs, but I would guess that
    FindClass() only returns null if an exception is
    thrown. And you are not checking for the exception.
    Which would tell you the problem.Ok, i'll remember that. But what with exceptions thrown in my java code, the documents say
    // jthrowable ExceptionOccurred(JNIEnv *env);
    // Determines if an exception is being thrown. The exception stays being thrown until either the native code calls ExceptionClear(), or the Java code handles the exception
    so, what if the java code throws an exception and catches it, will i be able to see that in my c++ code with ExceptionOccurred ?
    or
    should the java method be declared to throw the exception (and not catch it inside the method)
    Again, thank you for your help, it's greatly appreciated !

  • 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

  • Compile time errors for large code in try-catch blocks

    Hi, Has anyone ever faced this problem of a compile time error, where the Java compiler returns with the following error that Code is too large for try block.
    I have about 5000 thousand lines in my try-catch block and am facing this problem. Please suggest possible solutions

    1) Are you sure that your try/catch blocks contain 5 million lines?! I seriously don't believe this.Sounds like generated code. The generator needs to be a bit cleverer. In particular, it seems to be generating repeated blocks of code that ought to be stuffed into methods somewhere.

  • Try catch trouble

    hi all, im quite new to java and am having a bit of trouble with a try catch statement
    try
              System.out.println("Enter your level: ");
              level = data.nextInt();
              while (!VLevel(level))
         System.out.println("Enter your level: ", LEVEL);
                   dstfloor = read_in.nextInt();
              catch(InputMismatchException exception)
    System.err.println("Invalid level");
    continue;
    the problem i have is that when it triggers the exception, it just repeats the 'invalid level' line infinitely. any ideas?
    thanks

    If this line is causing an exception: dstfloor = read_in.nextInt();Then dstfloor's value will not change.
    Because you are using continue in the catch, the loop will run unfinately with dstfloor having the same value.
    You will need to modify the dstfloor var either in the catch or in the finally.
    Edited by: Azzer_Mac on Apr 24, 2008 9:08 AM

  • Doubt on try/catch exception object

    why it is not advisable to catch type exception in try catch block. Its confusing me. If i catch exception object then it will show whatever exception occured.
    btw, i was just go through duke stars how it works and saw this
    http://developers.sun.com/forums/top_10.jsp
    Congrats!

    Because there are many different kinds of Exception. If you have some specific local strategy for dealing with a particular excepion then you should be using a specific catch block.
    If you don't then you should allow the expection to end the program, and ideally you should deal with all the expceptions in one top-level handler, so you should throw, rather than catch the exceptions in your methods. Often at the outer most level of the program or thread you will actually catch Throwable (not just Exception) to deal with any unanticipated problems in a general kind of way.
    Also, you should be keeping track of what exceptions might be thrown, so that rather than using Exception in a throws clause or catch block, you should use the particular exceptions. Exceptions, generally, indicate a recoverable error that you really ought to be recovering from rather than just printing a stacktrace.
    That's why exceptions are treated differently from runtime errors.

  • Doubt try/catch/finally

    Hi all
    Say i have following program:
    try {
    line1.   functioncall()
    line2.    .....
    line3.    .....
    catch(..) {
    print error
    finally{
    System.out.println("In finally");
    }As per my understanding if there is some error in try block , then control will skip to catch and then to finally.
    And other way, if there is no error then all lines in try block will be executed and control has to go to finally block.
    And i see that there is no error (i have used try catch inside line1 function call also)
    Now I am facing this problem.
    In try block, line 1 is executed and getting into finally and there is also no error so it has skipped catch block. And in try block line2 and line 3 are skipped.
    Can anybody tell me why is it so.
    thanks
    Ravi

    What might be the problem?Sunspots. Not enough fiber. Government conspiracy.
    These are just guesses, which is all we can do unless you read and obey the following:
    Please post a short, concise, executable example of what you're trying to do. This does not have to be the actual code you are using. Write a small example that demonstrates your intent, and only that. Wrap the code in a class and give it a main method that runs it - if we can just copy and paste the code into a text file, compile it and run it without any changes, then we can be sure that we haven't made incorrect assumptions about how you are using it.
    Post your code between [code] and [/code] tags. Cut and paste the code, rather than re-typing it (re-typing often introduces subtle errors that make your problem difficult to troubleshoot). Please preview your post when posting code.

  • Error when using try catch inside oledb command to run stored procedure

    Hi,
    i'm using the below command to run some jobs  using OLEDB Command
    exec sp_start_job @job_name =?
    and it runs successfully
    when i put this code inside try catch block as below , it generates error and don't accept it
    begin try
    exec sp_start_job @job_name =?
    end try
    begin catch
    end catch
    the error message is "Syntax error, PErmission vaiolation or other nonspecific error"
    do you know is there any problem using TRY catch insdie OLEDB command ?
    Thanks ,
    Ahmed Salah

    Hi Ahmed,
    According to your description, if an error raised that fails the package, then you want the package to continue execute.
    To achieve this requirement, we can use Integration Services (SSIS) Event Handlers that we can create custom event handlers for an OnError event when an error occurs to continue processing rest of the package. For more details, please refer
    to the following blog:
    http://visakhm.blogspot.in/2013/03/error-handling-in-ssis-loops.html
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

Maybe you are looking for

  • HP Laserjet 6P delay in printing issue

    Long lapse of time between initiating "print" and HPLaserJet 6P actually printing. What could be causing delay?  Thanks for any help.

  • Problems in creating Invoice using BAPI

    Hello Friends, I am using a BAPI BAPI_BILLINGDOC_CREATEMULTIPLE to create invoice from a sales order, but i am not able to change the payer value. The payer is by default taken from Sales-Order, even if i change it in Payer value passed to BAPI. Plea

  • How do you get itunes to start working again after you get an error 7 message

    I keep getting the error 7 message when i try and open itunes i am not sure what i should do now. i have followed what they have listed on the website but it didnt change anything i am still getting the same message. HELP!!!

  • Communication between AS2 Template and AS3 Swf

    I created a template in AS2 which loads as2 swf's. i want to load as3 swf. then how can load as3 swf.within as2 template. please help me to find out this...

  • Quick Look Filter not working in OS 10.6.8

    I really like the ability to preview files by simply pressing the spacebar. I was able to do this fine on a previous iMac using OS 10.6.8, but when I installed the QuarkXpress.qlgenerator file on the new iMac running OS 10.6.8 it does not work unless