Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
How do you handle the exceptions ?
generic catch all statements are pretty much always wrong. -
@davidf98
How do you write your catch statements.
if you use C# for example then:
catch { ... } is wrong.
catch (Exception e) { ... } is also wrong. -
@ItsNotMyFault (reply to myself since i can't edit posts in the web app)
There are a few exceptions ofcourse (i.e, it can be ok to have a generic catch at the applications top level that catches anything that wasn't properly handled to be able to log the error before shutting down) -
davidf98967y@ItsNotMyFault I'm coding in Java and I'm using try{}catch(Exception e){...
The problem is that if I don't add the try/catch, the judge says RTE and if I add it, it says the output isn't correct. -
@davidf98
1) You should never catch the base exception class unless you want to perform some action before aborting the program in case of a serious error.
normally you want a try block that calls a single method and then one catch statement for each exception type that method explicitly throws.
i.e:
try { opensomefile }
catch (IOException e) { ... }
catch (SecurityException e) { ... }
finally { ... }
Never catch the base Exception class unless you intend to give up and abort or atleast rethrow it. catching the base exception class at the top level of your application to log any unhandled errors before the application dies is acceptable, doing it elsewhere is a bad idea. (How do you handle an exception properly without knowing what type of exception it is ? and if you're not handling it properly then the catch statement is basically just swallowing and hiding bugs in your code) -
Bad exception handling shouldn't affect the output of your application though, but it might hide the cause of the incorrect output.
-
davidf98967y@ItsNotMyFault Okey, thank you so much. I will keep looking for the error and I'll apply what u told me.
(still a lot to learn I guess)
Related Rants
-
linuxxx32*client calls in* Me: good morning, how can I help you? Client: my ip is blocked, could you unblock it for m...
-
DRSDavidSoft28Found this in our codebase, apparently one of my co-workers had written this
-
linuxxx23*client calls* "hello, we forgot the password to our WiFi router. Could you reset that for us?" 😐😶😮...
I'm trying to improve my code and I found a place where you can find problems and you can upload the answer and it says if it works or if it doesn't.
The funny thing is that it asks for handling the exceptions but it says it's wrong if u handle them.
undefined
paradox
wtf