Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9009993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:20:36+00:00 2026-06-16T02:20:36+00:00

I dont understand why I am getting this error at this line: Vehicle v

  • 0

I dont understand why I am getting this error at this line:

Vehicle v = new Vehicle("Opel",10,"HTG-454");

when I put this line in a try/catch, I usually dont get any error but this time try/catch block doesn’t work.

public static void main(String[] args)  {
  Vehicle v = new Vehicle("Opel",10,"HTG-454");

  Vector<Vehicle> vc =new Vector<Vehicle>();
  vc.add(v);

  Scanner sc = new Scanner(System.in);
  boolean test=false;
  while(!test) 
    try {
      String name;
      int i = 0;
      int say;
      int age;
      String ID;

      System.out.println("Araba Adeti Giriniz...");
      say = Integer.parseInt(sc.nextLine());

      for(i = 0; i<say; i++) {
        System.out.println("Araba markası...");
        name = sc.nextLine();

        System.out.println("araba yası...");
        age = Integer.parseInt(sc.nextLine());

        System.out.println("araba modeli...");
        ID = sc.nextLine();
        test = true;   

        vc.add(new Vehicle(name, age, ID));
      } 
      System.out.println(vc);
    } catch (InvalidAgeException ex) {
      test=false;
      System.out.println("Hata Mesajı: " + ex.getMessage());
    }           
  }     
}

and this is my constuctor in Vehicle class;

public Vehicle(String name, int age,String ID )throws InvalidAgeException{
        this.name=name;
        this.age=age;
        this.ID=ID;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:20:38+00:00Added an answer on June 16, 2026 at 2:20 am

    It must be It’s that the Vehicle constructor declares a checked exception. Your code calling it in main neither declares that checked exception nor handles it, so the compiler complains about it.

    Now that you’ve posted the Vehicle constructor, we can see that it declares that it throws InvalidAgeException:

    public Vehicle(String name, int age,String ID )throws InvalidAgeException{
    // here ---------------------------------------^------^
    

    Your main doesn’t declare that it throws InvalidAgeException, and you don’t have a try/catch around the new Vehicle, so the compiler won’t compile it.

    This is what checked exceptions are for: Ensuring that the code calling something either handles the exceptional condition (try/catch) or documents that it passes it on (via a throws clause).

    In your case, you’ll need to add a try/catch as you shouldn’t have main declaring checked exceptions, e.g.:

    public static void main(String[] args)  {
      try {
        Vehicle v = new Vehicle("Opel",10,"HTG-454");
        // ...as much of the other code as appropriate (usually most or all of it)...
      }
      catch (InvalidAgeException ex) {
        // ...do something about it and/or report it...
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am getting this error and i dont know why or understand the reason:
I dont understand why i am getting this on my php site Fatal error:
I don't understand why I'm getting this error. I used the same code previously
I don't totally understand how all this works, but I'm getting this error: Fatal
I keep getting this error message and I don't understand why: src\Parsing.hs:21:18: parse error
I'm getting this error on my program and I don't understand why. The code
I'm getting this, but I don't understand why.: A PHP Error was encountered Severity:
Sorry if this seems silly, I just cannot understand this runtime error I'm getting.
I don't understand why I keep getting this error message: Multiple annotations found at
Ok so, I'm getting this error when I try to use the asset pipeline.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.