| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 |
| 6 /** |
| 7 * This is a very simple sample app showing how to use the DirectoryProxy |
| 8 * interface. (See comments on DirectoryProxy for more explanation.) |
| 9 * |
| 10 * In this sample, we list the files in the directory that |
| 11 * is supplied on the command line. |
| 12 * |
| 13 * Then, we attempt to list the files in a directory that doesn't exist |
| 14 * (that is to show how exceptions pass back through the RPC |
| 15 * system). |
| 16 */ |
| 17 |
| 18 void main() { |
| 19 if (new Options().arguments.length < 1) { |
| 20 print("usage: out/Debug_ia32/dart_bin --enable_type_checks --enable_asserts
dir_sample.dart <path>"); |
| 21 return; |
| 22 } |
| 23 |
| 24 String path = new Options().arguments[0]; |
| 25 |
| 26 DirectoryProxy dir = DirectoryProxy.create(path); |
| 27 |
| 28 dir.isDirectory().then((bool isDir) { |
| 29 if (isDir) { |
| 30 print("${dir} is a directory, and contains these files"); |
| 31 dir.list().then((List<String> names) { |
| 32 for (String name in names) { |
| 33 print("found file ${name}"); |
| 34 } |
| 35 }); |
| 36 } else { |
| 37 print("${dir} is not a directory"); |
| 38 } |
| 39 }); |
| 40 |
| 41 // Here we deliberately use a bad path to show how an exception that |
| 42 // is thrown in the service isolate will be pass back through |
| 43 // the RPC system and can be caught in the main isolate. |
| 44 // |
| 45 // TODO(mattsh) - need a way to install a global exception handler |
| 46 // for an isolate. |
| 47 |
| 48 String badPath = "/path/that/does/not/exist"; |
| 49 |
| 50 print("an exception is expected here"); |
| 51 DirectoryProxy.create(badPath).list().then((List<String> names) { |
| 52 // won't reach here because an exception will be thrown |
| 53 assert(false); |
| 54 }); |
| 55 } |
| OLD | NEW |