On Mon, Feb 10, 2025 at 10:56:25AM -0500, Cole Robinson wrote: > On 2/4/25 3:08 AM, Richard W.M. Jones wrote: > > On Mon, Feb 03, 2025 at 02:35:20PM -0500, Cole Robinson wrote: > >> + | Guest_packages.Unknown_package_manager msg > >> + | Guest_packages.Unimplemented_package_manager msg -> > >> + error "%s" msg > > > > These exceptions can be thrown by Guest_packages.uninstall_command > > below, so you'll need to catch them. But I think this function > > (guest_pkgs_command) effectively disappears so the try/with clause > > moves into the next function: > > > >> + in > >> + > >> + let uninstall_packages pkgs = > >> + let cmd = guest_pkgs_command(Guest_packages.uninstall_command pkgs) in > > > > guest_pkgs_command goes away, but instead you need to catch the two > > exceptions that Guest_packages.uninstall_command can throw here. > > Thanks, these mails were very helpful and informative. One question > here, do all distinct errors need to be handled explicitly? Or is there > something like python > > try: > foo() > except Exception as err:
You've got full pattern matching syntax available, although because of the way these two exceptions are done it's not very useful in this case. So you could do: try ... with exn -> error "%s" (Printexc.to_string exn) But I wouldn't do that as it's best to let some exceptions escape and kill the program, things like out of memory or stack overflow. Note that the 'error' function (defined in common/mltools/tools_utils.ml) doesn't throw an exception, it calls exit. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v _______________________________________________ Libguestfs mailing list -- guestfs@lists.libguestfs.org To unsubscribe send an email to guestfs-le...@lists.libguestfs.org