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
Meena25Meena25 

script thrown exception

Having issues with below code: Error not showing up on lightning component

If (ownerUser != null){
            AuraHandledException e = new AuraHandledException('The application is already with team');
               e.setMessage('The application is already with team');
               system.debug(e);
            //catch(AuraHandledException e){
            throw e;
            //}
            //throw new AuraHandledException('The application is already with team');
        }

dandamudidandamudi
@Meena25 can you try and let me know if still issue occures
If (ownerUser != null){
String message = 'The application is already with team';
            AuraHandledException e = new AuraHandledException();
               e.setMessage(message);
               system.debug(e);
            //catch(AuraHandledException e){
			e.setMessage(message)
            throw e;
            //}
            //throw new AuraHandledException('The application is already with team');
        }

 
Meena25Meena25
Constructor not defined: [System.AuraHandledException].<Constructor>()
Raj VakatiRaj Vakati
Please handler your Aura exception in component 
 
action.setCallback(this, function(response){
                var state = response.getState();
                if(component.isValid()){
                    if (state == "SUCCESS") {
                        
                    }
                    else if (state === "ERROR") {
                        
                    }
                }
            });

 
dandamudidandamudi
@Meena this below code works for me , Please check again
Apex class:
If (ownerUser != null){
         throw new AuraHandledException('The application is already with team');
           
        }

Component controller.Js
action.setCallback(this,function(a){
        let state = a.getState();      
        if(state == "SUCCESS"){
           //Successs scenario
            });
          
        } else if(state == "ERROR"){
            let errors = a.getError();
         let toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                title: "Error",
                message: errors[0].message,
                type: "error"
            });
            toastEvent.fire();
        }
    });

 
Meena25Meena25
controller is fine but Apex class throws Script-thrown exception
Meena25Meena25
throw new AuraHandledException('The application is already with team'); this line in apex class
dandamudidandamudi
@Meena25 can you post your entore Apex method, so that i can fix against that
Meena25Meena25

I redid the entire code and i was able to resolve the issue @dandamudi

I handled the error handling in JS helper(client side). 

Now, even after having init in my lightning component still am seeing the popup with button name which i do not want it

I already have this in my lightning cmp <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

what else am i missing?

dandamudidandamudi
try this one too before post your method.
if(ownerUser != null){
    String m = 'The application is already with team';
    AuraHandledException e = new AuraHandledException(m);
    e.setMessage(m);
    throw e;
}