@@ -204,10 +204,14 @@ public Field getField(ClassLoader loader, FunctionCall<Field> functionCall) thro
204204 var methodName = getKeyName ();
205205 String value = sPrefsCacheHooks .getString (methodName , null );
206206 if (value == null ) {
207- Field result = functionCall .call ();
208- if (result == null ) throw new Exception ("Field is null:" + methodName );
209- saveField (methodName , result );
210- return result ;
207+ try {
208+ Field result = functionCall .call ();
209+ if (result == null ) throw new NoSuchFieldException ("Field is null" );
210+ saveField (methodName , result );
211+ return result ;
212+ } catch (Exception e ) {
213+ throw new Exception ("Error getting field " + methodName + ": " + e .getMessage (), e );
214+ }
211215 }
212216 String [] ClassAndName = value .split (":" );
213217 Class <?> cls = ReflectionUtils .findClass (ClassAndName [0 ], loader );
@@ -218,10 +222,14 @@ public Field[] getFields(ClassLoader loader, FunctionCall<Field[]> functionCall)
218222 var methodName = getKeyName ();
219223 String value = sPrefsCacheHooks .getString (methodName , null );
220224 if (value == null ) {
221- Field [] result = functionCall .call ();
222- if (result == null ) throw new Exception ("Fields is null: " + methodName );
223- saveFields (methodName , result );
224- return result ;
225+ try {
226+ Field [] result = functionCall .call ();
227+ if (result == null ) throw new NoSuchFieldException ("Fields is null" );
228+ saveFields (methodName , result );
229+ return result ;
230+ } catch (Exception e ) {
231+ throw new Exception ("Error getting fields " + methodName + ": " + e .getMessage (), e );
232+ }
225233 }
226234 ArrayList <Field > fields = new ArrayList <>();
227235 String [] fieldsString = value .split ("&" );
@@ -237,10 +245,14 @@ public Method getMethod(ClassLoader loader, FunctionCall<Method> functionCall) t
237245 var methodName = getKeyName ();
238246 String value = sPrefsCacheHooks .getString (methodName , null );
239247 if (value == null ) {
240- Method result = functionCall .call ();
241- if (result == null ) throw new Exception ("Method is null:" + methodName );
242- saveMethod (methodName , result );
243- return result ;
248+ try {
249+ Method result = functionCall .call ();
250+ if (result == null ) throw new NoSuchMethodException ("Method is null" );
251+ saveMethod (methodName , result );
252+ return result ;
253+ } catch (Exception e ) {
254+ throw new Exception ("Error getting method " + methodName + ": " + e .getMessage (), e );
255+ }
244256 }
245257 return getMethodFromString (loader , value );
246258 }
@@ -249,10 +261,14 @@ public Method[] getMethods(ClassLoader loader, FunctionCall<Method[]> functionCa
249261 var methodName = getKeyName ();
250262 String value = sPrefsCacheHooks .getString (methodName , null );
251263 if (value == null ) {
252- Method [] result = functionCall .call ();
253- if (result == null ) throw new Exception ("Methods is null:" + methodName );
254- saveMethods (methodName , result );
255- return result ;
264+ try {
265+ Method [] result = functionCall .call ();
266+ if (result == null ) throw new NoSuchMethodException ("Methods is null" );
267+ saveMethods (methodName , result );
268+ return result ;
269+ } catch (Exception e ) {
270+ throw new Exception ("Error getting methods " + methodName + ": " + e .getMessage (), e );
271+ }
256272 }
257273 var methodStrings = value .split ("&" );
258274 ArrayList <Method > methods = new ArrayList <>();
@@ -283,10 +299,14 @@ public Class<?> getClass(ClassLoader loader, FunctionCall<Class<?>> functionCall
283299 public Class <?> getClass (ClassLoader loader , String key , FunctionCall <Class <?>> functionCall ) throws Exception {
284300 String value = sPrefsCacheHooks .getString (key , null );
285301 if (value == null ) {
286- Class <?> result = functionCall .call ();
287- if (result == null ) throw new ClassNotFoundException ("Class not found: " + key );
288- saveClass (key , result );
289- return result ;
302+ try {
303+ Class <?> result = functionCall .call ();
304+ if (result == null ) throw new ClassNotFoundException ("Class is null" );
305+ saveClass (key , result );
306+ return result ;
307+ } catch (Exception e ) {
308+ throw new Exception ("Error getting class " + key + ": " + e .getMessage (), e );
309+ }
290310 }
291311 return XposedHelpers .findClass (value , loader );
292312 }
@@ -295,10 +315,14 @@ public Class<?>[] getClasses(ClassLoader loader, FunctionCall<Class<?>[]> functi
295315 var methodName = getKeyName ();
296316 String value = sPrefsCacheHooks .getString (methodName , null );
297317 if (value == null ) {
298- Class <?>[] result = functionCall .call ();
299- if (result == null ) throw new Exception ("Class is null: " + methodName );
300- saveClasses (methodName , result );
301- return result ;
318+ try {
319+ Class <?>[] result = functionCall .call ();
320+ if (result == null ) throw new ClassNotFoundException ("Classes is null" );
321+ saveClasses (methodName , result );
322+ return result ;
323+ } catch (Exception e ) {
324+ throw new Exception ("Error getting classes " + methodName + ": " + e .getMessage (), e );
325+ }
302326 }
303327 String [] classStrings = value .split ("&" );
304328 ArrayList <Class <?>> classes = new ArrayList <>();
@@ -312,10 +336,14 @@ public HashMap<String, Field> getMapField(ClassLoader loader, FunctionCall<HashM
312336 var key = getKeyName ();
313337 String value = sPrefsCacheHooks .getString (key , null );
314338 if (value == null ) {
315- var result = functionCall .call ();
316- if (result == null ) throw new Exception ("HashMap is null: " + key );
317- saveHashMap (key , result );
318- return result ;
339+ try {
340+ var result = functionCall .call ();
341+ if (result == null ) throw new Exception ("HashMap is null" );
342+ saveHashMap (key , result );
343+ return result ;
344+ } catch (Exception e ) {
345+ throw new Exception ("Error getting HashMap " + key + ": " + e .getMessage (), e );
346+ }
319347 }
320348 return loadHashMap (loader , key );
321349 }
0 commit comments