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
SfdcBlueFishSfdcBlueFish 

Exceptions?

Hai Friends,

 

 

      Can you please explain in which situation the following exceptions may raise?

 

              List index out of  bounds

 

              String out of bounds

 

              String exception: Satrting position out of bounds

 

              Dereference-the-null object

 

 

PLease explain the possible scenarios to get that exceptions

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

Here are your answers

 

               List index out of  bounds  : Your are trying to acces any index of list which is not in the list

               Ex : List size is 3 then list.get(0) , list.get(1) , list.get(2) , is ok

                       but list.get(3) will give you this error as max index is 2 so index given by you is out of bound

 

 

              String out of bounds

                     String str's length is 5 str ='abcde'

                       String s = str.substring(2 , 9);

               String will go out of bound       

 

              String exception: Satrting position out of bounds

                Ex : String str's length is 5 str ='abcde'

                       String s = str.substring(7 , 9);

                       max characte index is 4 so your startig index is out of bound

                       but list.get(3) will give you this error as max index is 2 so index given by you is out of bound

 

              Dereference-the-null object

                 String a = null;

                   String b = a.toLOwerCase(); // here you are trying to dereference a null object as a is null

 

All Answers

Shashikant SharmaShashikant Sharma

Here are your answers

 

               List index out of  bounds  : Your are trying to acces any index of list which is not in the list

               Ex : List size is 3 then list.get(0) , list.get(1) , list.get(2) , is ok

                       but list.get(3) will give you this error as max index is 2 so index given by you is out of bound

 

 

              String out of bounds

                     String str's length is 5 str ='abcde'

                       String s = str.substring(2 , 9);

               String will go out of bound       

 

              String exception: Satrting position out of bounds

                Ex : String str's length is 5 str ='abcde'

                       String s = str.substring(7 , 9);

                       max characte index is 4 so your startig index is out of bound

                       but list.get(3) will give you this error as max index is 2 so index given by you is out of bound

 

              Dereference-the-null object

                 String a = null;

                   String b = a.toLOwerCase(); // here you are trying to dereference a null object as a is null

 

This was selected as the best answer
SfdcBlueFishSfdcBlueFish

thanks for reply sharma,

 

          i need more possible scenarios.OK i understood from your answer how they are raising.But i want to know  kmore.

 

   Thank u sharma