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
111111 

how can i direct throw the errors?

 

how can i direct throw the errors?

 

for example

 

i got the error

unexpected token: throw

 

global class HelloWorld3 {

WebService static String sayHelloWorld(String userID, String userName) throw Exception{


Account c = [select account.name from account where name =:userName];

 

}

werewolfwerewolf
In the method header, the keyword is "throws", with an S, not "throw."

WebService static String sayHelloWorld(String userID, String userName) throws Exception{

Inside the method, when you want to throw an exception, that's when you use "throw" with no S.
111111

thank you for your replay

 

i also got the errors

 

unexpected token: throws

 

why?

 

global class HelloWorld3 {

WebService static String sayHelloWorld(String userID, String userName) throws Exception{

Account c = [select account.name from account where name =:userName];

c.name = 'Roth';update c;return 'Hello';}


}