java - Generic Exception Handling -


i found below code exception handling handles execptions of thrown application including runtimes.

      public static void handleexception(string strmethodname,                     exception ex) throws customexception{             string strmessage = "";             try {                 throw ex;             }              catch (nullpointerexception npe){                 logger.log(pr, strmethodname, npe.getmessage());                 strmessage=err_02;                 throw new customexception(strmessage);             }              catch(indexoutofboundsexception iobe) {                 logger.logmethodexception(strmethodname,iobe.getmessage());                 strmessage=err_03;                 throw new customexception(strmessage);             }             ... on      } 

below of disadvantages think:

  1. to idenitify root cause of exception need check message string.
  2. no sepearation of type of exceptions

advantage:

  1. less code. (code can minimized)

can please let me know whether should go such mechanism or not.

not sure of circumstances using code.

in approach, not rethrowing exception object may used debugging

public static void handleexception(string strmethodname,                     throwable th){             string strmessage = "";             try {                 throw th;             }              catch (throwable thr){                 logger.log(pr, strmethodname, npe.getmessage());                 //get appropriate error code method                 strmessage=geterrorcode();                 throw new customexception(strmessage, th);                 //customexception of type runtimeexception             }      } 

by catching , "throwing" throwable object sure errors handled properly. [it important not suppress throwable object]


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -