MIDRANGE dot COM Mailing List Archive



Home » JAVA400-L » October 2009

Showing root cause of error for Java tool box class which doesn't throw an exception



fixed

Hi all..



Does anyone have ideas how Java can report an error for a Java toolbox
class when it doesn't throw an exception? Is there any way to
programmatically dig out the cause when a method returns a value
indicating the underlying i5 operation failed, but doesn't throw an
error?



This code run on a windows server, it sets up the File objects to copy a
jpg image from the Windows server to an i5.



// ensure that parent dir of dest file exists!

IFSFile parent = new IFSFile(sys, parentPath);

if (!parent.exists()) {

parent.mkdirs();

}



try {

in = new FileInputStream(sourceFile);

} catch( IOException e ) {

throw new Exception ( "Problem with input file,
\""+sourceFile.getAbsolutePath()+"\" " + e.getMessage() );

}

try {

out = new IFSFileOutputStream(destFile);

} catch( IOException e ) {

throw new Exception ( "Problem with output file,
\""+destFile.getAbsolutePath()+"\" " + e.getMessage() );

}



Today the IFSFileOutputStream(destFile) started to throw errors.



The problem is caused by IFSFile.mkdirs() failing. It fails silently,
returning false.



I could change the code to:



if (!parent.exists()) {

if( !parent.mkdirs() ) {

throw new Exception("Unable to create parent folder,
\""+parent.getAbsolutePath()+"\" ) ;

}

}



That would notify the caller of the method that a failure took place,
but not the cause of the failure. parentPath is validated before the
execution gets this far so IFSFile.mkdirs() shouldn't fail in the first
place.



The failure is being caused by CPE3474, our IT department is working on
that.



I'd like to do something like this to report why IFSFile.mkdirs()
failed:



if (!parent.exists()) {

if( !parent.mkdirs() ) {

// do something to dig out cause of error

throw new Exception("Unable to create parent folder,
\""+parent.getAbsolutePath()+"\ caused by " + cause_of_error);

}

}



Any ideas what to replace the // do something... comment with?



Thanks

Bill Blalock

















_____________

The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.
_____________





Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact