0

Is there any method to get class name that through exception ?

Here is my code but I am unable to get the class name. Here is Complete code.

global class CustomLog{
global customlog()
{}

global static void customDebug(Exception ex){
    document d;
    list<document> doctoupdate = [select AuthorId,body,ContentType,FolderId,name from document where name = 'Data2'];
    system.debug('doctoupdate==='+doctoupdate);
    for(document dd: doctoupdate){
        d=dd;
        system.debug('d====='+d);
    }  
        if(d == null){
            d = new Document(); 
        }

         d.FolderId = UserInfo.getUserId();
         d.Name = 'Data2'; 
         system.debug('d.body==='+d.body); 
         String myContent = string.valueof(system.now())+  +'||'+ 'Classname:Student1' +'||'+ 'username'+ ':' +UserInfo.getUserName() +'||'+ 'Lineno:' +ex.getLineNumber() + '||'+ex.getMessage();

         string s1 = null != d.body?d.body.toString()+ '\n'+ +'\n'+ +mycontent:mycontent;
         system.debug('s1======='+s1);
         d.body = blob.valueof(s1); 
         d.ContentType = 'text/plain'; 
         d.Type = 'txt';
         upsert d;
}

Here is another class name Student1. I need whenever error occur on student1 its name caught in customlog class

public with sharing class Student1
{
   public Student__c stds;
   private ApexPages.StandardController controller;
   public list<string> a;
   integer num = 15;
   integer sum;

    public Student1(ApexPages.StandardController Controller) 
    {

        this.controller = controller;
    }

     public pagereference saveandget()
     {

        try
        {
            a.size();
        }

        catch(Exception ex)
        {
           if(ex!=null)
           {
               CustomLog.customDebug(ex);
           }
         controller.save();
         PageReference congratsPage = Page.student1;
         congratsPage.setRedirect(true);
        }

        try
        {
           sum = num/0;
        }

        catch(system.MathException ex)
        {
           if(ex!=null)
           {
               CustomLog.customDebug(ex);
               controller.save();
               PageReference congratsPage = Page.student1;
               congratsPage.setRedirect(true);
           }
        }   
            return null;

        }    

}
1
  • 1
    Seems you have an extra plus sign. Remove it and the string should be made with the class name you have added there
    – Eric
    Sep 19, 2016 at 7:23

1 Answer 1

1

It is problem in how you are closing String literal and concatenating:

Try below correction:

String myContent = String.valueof(system.now())+
                   '||Classname:Student1 || username:' +
                   UserInfo.getUserName()+ 
                   '||Lineno:' +
                   ex.getLineNumber()+ 
                   '||' +
                   ex.getMessage();

Also, you even didn't need to add + operator for some Strings joins.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .