function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SriramAravindSriramAravind 

Catching the line number of the code causing Exception

Hi,

 

          I want to write exceptions into UserExceptions custom object whenever the exception rises in my code for reference. I am doing that now for only exception message by using ex.getMessage().

          My idea is to display more information as much we can for developer reference like Line Number and the line of code causes exception.

 

Any idea on this please share. That would be helpful.

 

Regards,

Aravind.Sriramaneni

 

gv007gv007

1.use sytem.debug functionality. to display in debug log. It is useful for developers .

2.If want display to users use ApexPage class.

 

Note:it is not a good pratice handling the exception using catch and covering the bug instead of this try to slove the problem.

 

Gopi Ravoori.

Salesforce.com Pratice.

SriramAravindSriramAravind

Firstly thanks for your reply.

I am using debug statements to solve exceptions.

We can’t come to know the exceptions which are potentially raise in Production in prior. For that reason I have created on custom object called UserExceptions and writing them into that.

Now I am able to write just an exception message. And I want to be written the line number of the code which causes the exception.

wesnoltewesnolte

Hey

 

As far as I know this isn't possible. What we do is maintain a string var within our class e.g. String debug_msg, and then set the value of this string before we do anything programmatically. So

 

debug_msg = 'Entering loop';

For(...)

 

debug_msg = 'Entering if';

if()

debug_msg = 'In first branch';

 

 

etc.

 

Obviously you can make these messages a bit clearer to the reader but you will need to perform some extra work as a developer.

 

Cheers,

Wes 

SriramAravindSriramAravind

 

Thanks Wes for your quick reply. 

I am going to Implement your idea.