changeset 33144:d043168d4cf2 stable

methods.m: Emit sensible error message if Java not installed or classname does not exist (bug #65408) * methods.m: Use try/catch block to test whether Java classname exists. If try block fails, because Java is not installed or the classname does not exist, then throw an error about the classname not being found. Add BIST test for bug #65408.
author Rik <rik@octave.org>
date Mon, 04 Mar 2024 12:35:12 -0800
parents e006d8ce57b5
children a92f3c0c92d9 beae4d70e218
files scripts/miscellaneous/methods.m
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/methods.m	Mon Mar 04 15:27:33 2024 -0500
+++ b/scripts/miscellaneous/methods.m	Mon Mar 04 12:35:12 2024 -0800
@@ -60,14 +60,19 @@
   endif
 
   if (isobject (obj))
-    ## Call internal C++ function for Octave objects
+    ## Call internal C++ function for Octave objects.
     mtds_list = __methods__ (obj);
   elseif (ischar (obj))
-    ## Could be a classname for an Octave class or Java class.
+    ## CLASSNAME could be an Octave class or Java class.
     ## Try Octave class first.
     [mtds_list, valid] = __methods__ (obj);
     if (! valid)
-      mtds_str = javaMethod ("getMethods", "org.octave.ClassHelper", obj);
+      ## Try Java class second.
+      try
+        mtds_str = javaMethod ("getMethods", "org.octave.ClassHelper", obj);
+      catch
+        error ("methods: class '%s' not found", obj);
+      end_try_catch
       mtds_list = ostrsplit (mtds_str, ';');
       mtds_list = mtds_list(:);  # return a column vector for compatibility
       havesigs = true;
@@ -158,4 +163,5 @@
 ## Test input validation
 %!error <Invalid call> methods ()
 %!error <invalid option> methods ("ftp", "option1")
+%!error <class 'foobar' not found> methods ('foobar')
 %!error <invalid input argument> methods (1)