I'm trying to write a simple method to extract the package version (using System.requestVersion()
) and convert it to a string. The documentation for that method indicates that it will throw an exception if called from an unmanaged package. I've since found that it's throwing a System.ProcedureException
.
But I can't figure out how to either:
- Determine if I'm in a managed package before trying to call the method.
- Catch the exception so I can return
null
to the caller.
The code below throws a System.ProcedureException: Method is not supported from an unmanaged namespace
on the line calling System.requestVersion()
but it isn't caught by the catch
block for some reason.
public static String packageVersion()
{
try
{
System.Version v = System.requestVersion();
String versionString = v.major() + '.' + v.minor();
if (v.patch() != null)
{
versionString += '.' + v.patch();
}
return versionString;
}
catch (Exception e) { /* ignore exceptions and return null */ }
return null;
}
I've tried both catching all exceptions (shown above) and just catching System.ProcedureExceptions
. Both fail to catch.
Looking for help with either of the bullet points at the top of the question -- code to know if it's safe to call, or a way to catch the exception.