I have the following function in a Service class
protected function writeToFile():void{
var destinationFile:File = File.applicationStorageDirectory.resolvePath(_newPath);
var fs:FileStream = new FileStream();
fs.open(destinationFile, FileMode.WRITE);
fs.writeBytes(_buffer, 0, _buffer.length);
fs.close();
}
this Service class should dispatch a SuccessfulCreateLocalFileEvent when writeToFile is successful and an UnsuccessfulCreateLocalFileEvent if writeToFile is unsuccessful.
I know that FileStream functions open and writeBytes may throw IOError if there is any problems. And all these FileStream functions all have void as return types.
I believe I need try catch, but I am not entirely sure how to do so.
Please advise.
This question is replicated at http://knowledge.robotlegs.org/discussions/questions/924-what-is-best-way-to-write-dispatch-events-in-this-service-class-function Experimenting which site has better answers for such a question.