Find your content:

Search form

You are here

String Exception is not being caught?

 
Share

Some how nothing is being caught. Not sure, but it could be not understanding how exception really works. So I have a method that does everything including querying, than finally does an update to an opportunity record

public void createAlert(){
    try{
        for (List<OpportunityLineItem> oliList : [Select oli.id from OpportunityLineItem oli Where oli.OpportunityId = :oppId]){

        //some logic
        }   
        //some logic
        update updateOpp;
    } catch (System.StringException e) {
        system.debug('Exception===>' + e.getMessage());
    }                                                   
}

I am invoking this method from the develop console right now like this :

Alert opp = new Alert('aaaaaaaaa');
opp.createAlert(); 

I get this error:

11:36:07:147 FATAL_ERROR System.StringException: Invalid id: aaaaaaaaa

But it never caught the exception, so I never got the "Exception===>" debug message.


Attribution to: MCHam

Possible Suggestion/Solution #1

It's a little lazy, but instead of catching specifically the StringException, you could just catch Exception, which is a catch-all bucket:

} catch (Exception e) {
    system.debug('Exception===>' + e.getMessage());
}   

Is that sufficient for your needs?

Also, your constructor is expecting an Id - and you are not passing in a valid Id. Salesforce does check Ids for legitimate formats. Pass in something that will pass the test, such as 005000000000000000.


Attribution to: DavidSchach
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33486

My Block Status

My Block Content