Skip to main content
Inspiring
July 21, 2013
Answered

File I/O Error not trapped by Event Listener

  • July 21, 2013
  • 1 reply
  • 1114 views

Doesn't appear that File I/O error is trapped by the IOErrorEvent.IO_ERROR event

as described in all the documentation and samples I've looked at.

My test code is listed below - if the P drive does not exist it generates a File I/O error (#2038)

which it should - but it doesn;'t get trapped in File event.

Here's the simple test code attached to a button

public function btnSubmitSafetySheet_clickHandler(event:MouseEvent):void
    var pdfFilter:FileFilter = new FileFilter("PDF Files", "*.pdf");                

    var tmpPDF:File = File.documentsDirectory.resolvePath("rpt_RegionalManagers.pdf");

    var copyToMissingFolder:File = new File();

    copyToMissingFolder.nativePath = ("P:/safety/Initials-DDMMYYYY-SafetySheet.PDF");  

    trace(copyToMissingFolder.nativePath);

    if (copyToMissingFolder.exists) {

        trace('MissingFolder exists');

    }

    else {

        trace('MissingFolder DOES NOT exist');

    }

    tmpPDF.addEventListener(IOErrorEvent.IO_ERROR, pdfCopyError)

    tmpPDF.copyTo(copyToMissingFolder, true);                       // Should Generate I/O Error if P: not available                                      

    trace('copied to missing docs folder');

}

private function pdfCopyError(evt:IOErrorEvent):void {

    trace('PDF Copy From Network Error');

    trace('Error Message: ' + evt.text);

    removeFileListeners();

}

No trace messages from the IOErrorevent function - just the debug and Error:

P:\safety\Initials-DDMMYYYY-SafetySheet.PDF

MissingFolder DOES NOT exist

Error: Error #2038: File I/O Error.

    at flash.filesystem::File/copyTo()

This topic has been closed for replies.
Correct answer Damanjit Singh

Hi,

There are two different things -

1. IOError

2. IOErrorEvent

Errors (including IOError) are thrown synchronously and must be caught using the try/catch statements. Infact, copyTo method's documentation clearly states that it thorows IOError, so you should use it inside try / catch statement to catch it.

Events (including IOErrorEvent) are thrown asynchronously, for operations which are performed asynchronously. For e.g. copyToAsync method, as documented, may cause generation of complete and ioError events. Where as copyTo method does not cause any events (again already documented).

1 reply

Participating Frequently
July 21, 2013

ok ,infact i don't think it's a bug . i think you mis understand the  I/O error  in this situation.

Inspiring
July 21, 2013

Explain to me what is the proper meaning and correct understanding

The error is Error #2038: File I/O Error.

Right from context-help in Flashbuilder for the IO_ERREVENT

The operating system did not allow the operation; or the file or directory does not exist.
On Windows, you cannot move a file that is open or a directory that contains a file that is currently open.
Damanjit SinghCorrect answer
Adobe Employee
July 22, 2013

Hi,

There are two different things -

1. IOError

2. IOErrorEvent

Errors (including IOError) are thrown synchronously and must be caught using the try/catch statements. Infact, copyTo method's documentation clearly states that it thorows IOError, so you should use it inside try / catch statement to catch it.

Events (including IOErrorEvent) are thrown asynchronously, for operations which are performed asynchronously. For e.g. copyToAsync method, as documented, may cause generation of complete and ioError events. Where as copyTo method does not cause any events (again already documented).