Learn to Code via Tutorials on Repl.it!

← Back to all posts
Java Exceptions Made Quick
Jakman (454)

Are you tired of having to write try/except blocks or importing Exceptions?. Here is a really good trick that I found whilst analyzing the syntax of Java. Try this.

public class exampleclass {
    public static void main(String[] args) throws Exception{
        //example code 
    }
}

In the main method i had put in throws Exception.
That means that a generic Exception is thrown all through the main method. Therefore there is no need for try except. Try my style of work. This concludes my Ted Talk, thanks for being a good audience.

Comments
hotnewtop
studentAlfredAl (449)

Thanks for the tutorial! :) I also found out there's a way to print text at whatever speed you want in Java, as well as time anything you want. You can also do public static void main(String[] args) throws InterruptedException {
This will allow you to do many things with timing. :)

Jakman (454)

@studentAlfredAl Cool. Ill see about that sometime.

Jakman (454)

@studentAlfredAl hey man I am making an awesome java swing tool. Would you like to help? It uses interfaces.

studentAlfredAl (449)

Hey @Jakman so sorry for the late reply. I actually have no clue about java swing tools, so I'm not sure I'll be of much help. If possible, I'll try to help though :)

Razia86 (1)

Haha never thought about it this way, always thought try and catch blocks go together and needed for exception.

Jakman (454)

@Razia86 yeah they can be used to broaden your mind about java syntax rules.

EpicGamer007 (1765)

I like this way but the only problem I have with this is that every method that uses this method has to have "throws exception" and the methods above that which means that If you have a class with a method called slowPrint, then the method that uses that method would have to throw that exception and the method that uses the method that was just used would have to throw that exception and it continues like that all the way to the main method. this is good if you are making a small program with a few methods but not good if you want larger ones.

Imagine if you had a large program where you use slowprint a lot. That would be waayyy more writing...

Jakman (454)

@AbhayBhat just use threading then man.

Jakman (454)

@AbhayBhat would you like me to give you a crash course on java. I have read your description.

EpicGamer007 (1765)

@Jakman Yeah that would be great! I mean, I guess I can learn a few things. Also, I do not need to learn basic stuff(print, scanner, etc.), maybe advanced stuff would work. I would appreciate if you could make a project and share it with me :)

P.S. - I have noticed that your pfp is Tien, why tien(DBZ was the first anime I have ever watched)

Jakman (454)

@AbhayBhat cool. Tell me when you want to join.

Jakman (454)

@AbhayBhat shoot i keep falling asleep. You here? I'll teach now...

EpicGamer007 (1765)

@Jakman Hey, I can learn now, just had to do some Math HW

Jakman (454)

@AbhayBhat alright.
Ill invite you too an advanced project that me and another worked on. I have had a bad schedule this week so i hope this time can count.

EpicGamer007 (1765)

@Jakman Hey My repl crashed and now i cannot get on our project. are you able to access it(I get a 404 error).

Jakman (454)

@AbhayBhat yeah
let me just make another project and transfer everything to the other project

Jakman (454)

@AbhayBhat i still can. Ill try to re invite you.

Jakman (454)

@AbhayBhat i still can. Ill try to re invite you.

Jakman (454)

@AbhayBhat i can. Let me try to re invite you.

EpicGamer007 (1765)

@Jakman hey, i think the original works now

Jakman (454)

@AbhayBhat ok. ill go to the original

EpicGamer007 (1765)

@Jakman Yeah, the original works now

Jakman (454)

@AbhayBhat you wanna finish the project w/ me?

EpicGamer007 (1765)

@Jakman Yeah, sure
IDK how much time I have but I think I will be able to do quite a lot to today

EpicGamer007 (1765)

@AbhayBhat, It says ur online but you are not responding?

Jakman (454)

@AbhayBhat hey im back onnline. thanks for being patient.

EpicGamer007 (1765)

@Jakman Hey im back, i finished eating