Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

illegal start of expression when declaring method that throws an exception  RSS feed

 
Bud Tippins
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting an error when I try to declare a method that throws en exception. The error that NetBeans shows on line #13 is "illegal start of expression." What is wrong with line #13?

Any help greatly appreciated.



 
Stephan van Hulst
Saloon Keeper
Posts: 7804
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bud. You are missing a brace in your main method.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And your if statement is incorrect.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote:And your if statement is incorrect.

There are actually two problems with the if statement. The one will be easy to spot because the compiler will give an error.
The other is a bit more difficult because once all the compiler errors are fixed, the code will actually work how the OP expects.

Bud - once you have the program compiling, run it and it should work as you expect. Now try changing line 6 toand see what happens.
 
Louis Cheung
Greenhorn
Posts: 9
jQuery Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,Bud!I just found 2 mistakes in your program.Hope my tips could be helpful.
First,the IF statement should be in lower case.
Then,when you tried to throw an exception in a method,you should use "throw new xxxException();"
 
Campbell Ritchie
Marshal
Posts: 55681
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You found two problems with the if statement, but as Joanne Neal has already said, there is a more serious problem, which you have not noticed.
 
Bud Tippins
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your help.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So did you fix the problem I was hinting at ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!