Jump to content

I'm asking here because I can't find it on Google on what codes/types are they

Q1:is the type of exception thrown when a application stops running before its natural end.
Q2:User Exceptions are exceptions that are manually thrown by the programmer using what?
Q3:can the 'trycatch' block be nested?
LastQ: Can Exceptions be generated through methods calls? if not .. what can?

Thanks in Advance for those who can answer :)

CPU: Intel Core i7-4790K @ 4.0GHz | COOLING: Corsair H100i Liquid Cooler | MOTHERBOARD: ASUS Maximus VII Formula ATX | MEMORY: Corsair Vengeance Pro Series 16GB (2 x 8) DDR3-1866 | STORAGE: Intel 730 Series 480GB SSD + Seagate Barracuda 3TB HDD | PSU: Corsair AX860i 80+ Platinum | GPU: ASUS GeForce GTX 780Ti DirectCU II (2-Way SLI) | CASE: Phanteks Enthoo Luxe (Black) | DISPLAY: ASUS PB278Q 27.0" (2560 x 1440) | KEYBOARD: Razer BlackWidow Chroma | MOUSE: Razer Deathadder Chroma | SOUND: Logitech Z906 5.1 Speakers / Razer Kraken Chroma | OS: Microsoft Windows 8.1 (64-bit)

Link to comment
https://linustechtips.com/topic/300484-java-questions/
Share on other sites

Link to post
Share on other sites

Not trying to be an asshole but it looks like an assignment or homework maybe it is maybe it isn't, is it?

Current rig: CPU: AMD FX-8120  Cooling: Corsair H100i  Mobo: ASRock 970 Extreme 3  RAM: 8GB 1333Mhz  GPU: MSI GTX 660Ti Power Edition  Case: Fractal Design Define R4  Storage: 2TB Seagate HDD + 128GB Crucial SSD  PSU: be quiet! 730W bronze

 

Link to comment
https://linustechtips.com/topic/300484-java-questions/#findComment-4082045
Share on other sites

Link to post
Share on other sites

Not trying to be an asshole but it looks like an assignment or homework maybe it is maybe it isn't, is it?

Honestly, there the questions in an exam I'm about to take that I can't find the answers for. If you can't help I understand it's kind of cheating i know but I would want to get a higher grade

CPU: Intel Core i7-4790K @ 4.0GHz | COOLING: Corsair H100i Liquid Cooler | MOTHERBOARD: ASUS Maximus VII Formula ATX | MEMORY: Corsair Vengeance Pro Series 16GB (2 x 8) DDR3-1866 | STORAGE: Intel 730 Series 480GB SSD + Seagate Barracuda 3TB HDD | PSU: Corsair AX860i 80+ Platinum | GPU: ASUS GeForce GTX 780Ti DirectCU II (2-Way SLI) | CASE: Phanteks Enthoo Luxe (Black) | DISPLAY: ASUS PB278Q 27.0" (2560 x 1440) | KEYBOARD: Razer BlackWidow Chroma | MOUSE: Razer Deathadder Chroma | SOUND: Logitech Z906 5.1 Speakers / Razer Kraken Chroma | OS: Microsoft Windows 8.1 (64-bit)

Link to comment
https://linustechtips.com/topic/300484-java-questions/#findComment-4082077
Share on other sites

Link to post
Share on other sites

The answer to question 3 is yes. The other questions do not make sense.

  1. Exceptions can't be thrown after a program stops running. And any type of exception may cause a program to stop execution if it is not caught. This question makes no sense.
  2. Exceptions are thrown, period, not "by" anything. This questions makes no sense.
  3. Sure. It is usually an bad way of doing things, though.
  4. Exceptions can be "thrown" in a method, I guess that is the same thing as "generated"? This question doesn't make any sense, either.

Good luck with your cheating.

Link to comment
https://linustechtips.com/topic/300484-java-questions/#findComment-4082895
Share on other sites

Link to post
Share on other sites

I don't consider that cheating.. He's just asking questions before a test, that's normal. However as @SSL said q1/2 make no sense, agree with him on q3 and about q4... Please do some simple main methods in which you throw exceptions so you Can understand them better. I'm on a mobile device right now so I can't write full examples but consider something like :

System.out.orintln("1");

throw new RuntimeException();

System.out.println("2");

And see what your compiler will tell you.

Also you can write a program which does the same but uses a random generator and throws the exception 50 percent of the time. I think those two will help you understand better how exceptions work.

CPU: Ryzen 3 3600 | GPU: Gigabite GTX 1660 super | Motherboard: MSI Mortar MAX | RAM: G Skill Trident Z 3200 (2x8GB) | Case: Cooler Master Q300L | Storage: Samsung 970 EVO 250G + Samsung 860 Evo 1TB | PSU: Corsair RM650x | Displays: LG 27'' G-Sync compatible 144hz 1080p | Cooling: NH U12S black | Keyboard: Logitech G512 carbon | Mouse: Logitech g900 

Link to comment
https://linustechtips.com/topic/300484-java-questions/#findComment-4083757
Share on other sites

Link to post
Share on other sites

I think he's talking about RuntimeExceptions, which don't have to be caught by the compiler (like ArrayIndexOutOfBoundsException) and are thrown at run time.

 

User exceptions could be like:

public int addPositiveNumbers(int x, int y) {

if (x < 0 || y < 0) {

throw new InvalidArgumentException();

}

 

return x + y;

}

 

Stupid question, but he's probably looking for the "throw" keyword. You should also know what "throws" means (Hint: it's not used within a method call).

 

try {

} catch()

 

blocks can be nested. I did it on a regular basis to tie up files. Usually you try { open file } catch( some error ) { } finally { close file/release resources }. This is a bit different now since many Java classes include "closable" interface which means it will release the resources for you... try (BufferedReader reader = new BufferedReader(...)) { reader.readLine()... }

 

I don't understand your last question: Can Exceptions be generated through methods calls? if not .. what can?

Is he talking about exception propagation, i.e., if an exception is thrown by a method, it is passed back up the stack until it reaches your original method call, where you need to catch and address it? If so, then yes: exception propagation. Else I don't know what the hell he's talking about.

Link to comment
https://linustechtips.com/topic/300484-java-questions/#findComment-4109295
Share on other sites

Link to post
Share on other sites

I'm asking here because I can't find it on Google on what codes/types are they

Q1:is the type of exception thrown when a application stops running before its natural end.

Q2:User Exceptions are exceptions that are manually thrown by the programmer using what?

Q3:can the 'trycatch' block be nested?

LastQ: Can Exceptions be generated through methods calls? if not .. what can?

Thanks in Advance for those who can answer :)

 

1. An exception that causes an application to stop running before it's normal end is an uncaught runtime exception.

 

2. Typically: throw new ExceptionClass; where ExceptionClass is a class derived from the Exception class.

 

3. Try/catch blocks can be nested, but each try must have either a catch or finally block with it.

 

4. There are exceptions that can be generated through method calls, and these would be due to incompatibilities between jars within the classpath. An example is the ClassNotFoundException exception.

Wife's build: Amethyst - Ryzen 9 3900X, 32GB G.Skill Ripjaws V DDR4-3200, ASUS Prime X570-P, EVGA RTX 3080 FTW3 12GB, Corsair Obsidian 750D, Corsair RM1000 (yellow label)

My build: Mira - Ryzen 7 3700X, 32GB EVGA DDR4-3200, ASUS Prime X470-PRO, EVGA RTX 3070 XC3, beQuiet Dark Base 900, EVGA 1000 G6

Link to comment
https://linustechtips.com/topic/300484-java-questions/#findComment-4115261
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×