简体   繁体   中英

How can I check error code in Gnome/gjs/Gio

This doesn't work (nothing happens when the directory exists):

let s_dir = Gio.file_new_for_path("./S1");
try {
        s_dir.make_directory(null);
} catch(e) {
        if(e == Gio.IOErrorEnum.EXISTS)
            print(e);
}

Use the GLib.Error.matches() method:

let s_dir = Gio.file_new_for_path("./S1");
try {
        s_dir.make_directory(null);
} catch(e) {
        if (e.matches (Gio.IOErrorEnum, Gio.IOErrorEnum.EXISTS)
            print(e);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM