sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Catch blocks not being excuted when running on IFS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Catch blocks not being excuted when running on IFS

    I have a Java program that connects to the AS400 and tries to read a file and convert it to xml. This works fine, but sometimes I expect the file to not be there, in which case I catch an exception and do a couple things like log that the file wasn't found.

    This all works great when running from my desktop, but once I put it on the IFS under the /HOME/ directory, the catch blocks are never executed. If all files that are passed in are valid, it runs fine, but if any files aren't found, that thread seems to just stop and close after an exception is thrown instead of executing the code in the catch block. Has anyone run into anything like this before? This is being called from a CLP using a shell script.

    Code:
    public void run() {
            String targetName = "";
            String targetType = null;
            String type = "";
            IFSFile source = null;
            IFSFileOutputStream target = null;
            GZIPOutputStream targetZip = null;
    
            
            log.info("Starting new thread with source file " + sourceName);
            
            //set up target file.
            targetName = sourceName.substring(0, sourceName.lastIndexOf("/") + 1) + "XML/";
            type = sourceName.substring(sourceName.lastIndexOf("/") + 1, sourceName.indexOf("2"));
    
            //... Some code to detect what the name of the output file should be....
    
            targetName = targetName + targetType
                    + sourceName.substring(sourceName.indexOf("2"), sourceName.lastIndexOf(".")) + ".xml.gz";
    
            Date date = new Date();
            Timestamp time = new Timestamp(date.getTime());
    
            AS400 as400 = null;
    
            try {
                as400 = new AS400(system, "GPUPDUSR", "N0T4L0NG");
                log.info("Connected to AS400 System: " + system + " for XML creation of type " + type);
                
                
                //Open source file
                source = new IFSFile(as400, sourceName);
                
                //read file
                BufferedReader readBuffer = new BufferedReader(new IFSFileReader(source));
                log.info("Source file successfully opened at " + sourceName);
    
                //Open target file
                target = new IFSFileOutputStream(as400, targetName, IFSFileOutputStream.SHARE_NONE, false);
                targetZip = new GZIPOutputStream(target);
                log.info("Target file successfully opened at " + targetName);
    
                
                
               // ... Call corresponding method to generate XML based on type
                
                //Using a synchronized counter to help detect when the last thread is finished
                Main.count.increment(as400, this);
                
    
                //clean up
                readBuffer.close();
                targetZip.close();
                Date date2 = new Date();
                Timestamp time2 = new Timestamp(date2.getTime());
                log.info(type + " XML process ended succesfully. Started at " + time.toString() + " and finished at "
                        + time2.toString());
    
                log.info("Thread for " + type + " disconnected from " + system);
                as400.disconnectAllServices();
    
            } catch(ExtendedIOException fnf) {
    
                System.out.println("Made it to the file not found catch");
                log.warn("File " + source + " was not found/empty.  Skipping this dimension.  Closing AS400 connection for this thread.");
                Main.count.increment(as400, this);
                as400.disconnectAllServices();
                
            } catch (Exception e) {
    
                System.out.println("Made it to the random exception catch");
                log.error("Something unexpected happened.", e.fillInStackTrace());
                Main.count.increment(as400, this);
                as400.disconnectAllServices();
    
            }
        }
    EDIT:
    So I moved the
    Code:
     Main.count.increment(as400, this);
     as400.disconnectAllServices();
    to a finally block at the end and that seems to work, and I also changed it to actually check if the file exists with source.exists() (duh) and write a warning if it doesn't. But it still will never execute the catch block if something unexpected happens.
Working...
X