cancel
Showing results for 
Search instead for 
Did you mean: 

How to log an exception?

Former Member
0 Kudos

Hi,

I'd like to trace an exceptionstack to a category. How should I do this? If I write "e.printStackTrace" I cannot supply any category.

Should I use "e.getStackTrace()" and log each single line of the array this method delivers?I do not think that this is a good idea.

Thanks for each hint,

Christoph

Accepted Solutions (1)

Accepted Solutions (1)

former_member182294
Active Contributor
0 Kudos

Hi Christoph,

I am assuming that you have configured categories for Logging in Visual Admin. Once the categories are created in VA do the following in your code:

com.sap.tc.logging.Category appCategory = Category.getCategory(Category.APPLICATIONS, "category_name");

public static final com.sap.tc.logging.Location logger = 	com.sap.tc.logging.Location.getLocation(YourClass.class);

try
{
//logic here
}
catch(XXXException exe)
{
     logger.fatalT(exe.getMessage(),exe.getStackTrace());
}

Hope this will solve your problem.

Regards

Abhilash

Former Member
0 Kudos

Hi Abhilash,

it does not work because there is not method defined with signature fatalT(String, StackTraceElement[]).

Regards,

Christoph

Former Member
0 Kudos

Solution is simple:

import com.sap.tc.logging.Category;
import com.sap.tc.logging.Location;

class <className> {
   private static Category _cat = Category.getCategory(Category.getRoot(), <categoryName>);
   private static Location _loc = Location.getLocation(<locationName>);
   ...
   public void myMethod() {
   try {
      <some code>
   catch (Exception e) {
      _cat.logThrowableT(Severity.ERROR, _loc, e.getMessage(), e);
   }
}

Regards,

Christoph

Answers (1)

Answers (1)

Former Member
0 Kudos

marked as solved

former_member182294
Active Contributor
0 Kudos

Hi,

I agree throwableT (...) solves your problem but as you said there is no direct method fatalT(String, StackTraceElement[]) but fatalT(String, Object[]) accepts any kind of object. And also if you look at the StackTraceElement, toString() method is overridden with the exception details so when you pass StackTraceElement[] inside the fatalT() obviously it prints the same message.

Regards

Abhilash