Questions tagged [try-catch]

try-catch is used to catch the exception.

Filter by
Sorted by
Tagged with
66
votes
5answers
9k views

Pokemon Catch - Generic Exception Handling In Apex

I read a great post about this topic on Stack Overflow: Is it really that bad to catch a general exception? However, I asked this question on our exchange because I am interested in a more specific ...
7
votes
1answer
3k views

Catch Regex too complicated when splitting a string in salesforce

I have created a function wherein I split a string from the csv filecsvAsString.split('\n') . It is working when the string is not so big. But when I try to split a very large string, an error will ...
14
votes
3answers
5k views

Can I throw an exception in apex and still log the caught exception?

I'm really wrestling with the best error handling strategy. My goal is to handle all exceptions that I can identify, log them to a table in the database, and surface a helpful message about what ...
3
votes
1answer
3k views

Custom Exception Handling & Logging

I've set out to build a custom error handling and logging feature for my org wherein all apex exceptions will be logged into a custom sObject for analysis and follow-up. public class TriggerException ...
2
votes
3answers
118 views

Coverage for Catch Block (cant generate exception in try{}) give another solution

NOTE : This question is not duplicate.Please go through code once. Here is the situation - I am calling this method from my test class, and here My_obj__c records are getting created and added in ...
10
votes
1answer
4k views

Catch System.AssertException

Is there a way to catch System.AssertException? For example, some class is known to throw assertions in certain cases and it's ok to deal with that on some upper level. But unfortunately ...
-1
votes
1answer
41 views

Unable to cover try catch for UserPackageLicense test class

I have below UserPackageLicense class and test class.I am unable to cover the test class try catch block Class:- public class AssignPackageLicense { public static boolean flag=true; static String ...