• Post Reply Bookmark Topic Watch Topic
  • New Topic

try blocks in main  RSS feed

 
Abigail Decan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i tried this code in BlueJ IDE.
it told me i had an illegal beginning for "try".
what did i do wrong?
am i not supposed to use try for main methods?
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are multiple errors with the code :

1: try has to be within a block or method i.e {} but you used try inside class. so it'll not be executed..
2: catch should also be within block you've used both try and catch within class (i.e they are not associated with any method or block).
3: catch block isn't catching any exception. Use a variable of exception type to catch it.

Use try and catch inside main and it'll work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!