Java Throwing Exception - Best Practise
up vote
-1
down vote
favorite
What is the best practice to throw the error message?
As soon as I throw the exception, the exception has been traced in the errorlog.log file. I have more custom exception. If I throw these exceptions, for all the incorrect attempt, it will be traced in the logfile and it bugs the file and increasing the log file size.
what is the good way of doing this? Is it mandatory in java that we have to do the programming like this?
I want most of my custom messages like single line of error and very critical error should be thrown with complete error trace.
Need suggestion on error handling and tracing the log.
java exception error-handling
add a comment |
up vote
-1
down vote
favorite
What is the best practice to throw the error message?
As soon as I throw the exception, the exception has been traced in the errorlog.log file. I have more custom exception. If I throw these exceptions, for all the incorrect attempt, it will be traced in the logfile and it bugs the file and increasing the log file size.
what is the good way of doing this? Is it mandatory in java that we have to do the programming like this?
I want most of my custom messages like single line of error and very critical error should be thrown with complete error trace.
Need suggestion on error handling and tracing the log.
java exception error-handling
3
You should look into the logging frameworks likeslf4j
orlog4j
. They offer different logging levels, which exceptions might trigger. A severe message would only be logged for very serious exceptions.
– Tim Biegeleisen
Nov 10 at 14:11
It’s not a rule of life that every exception thrown is logged. I’d rather say it’s bad practice to so indiscriminately. I don’t know why your exceptions are, but it must come from a mechanism that is specific to your system.
– Ole V.V.
Nov 10 at 14:47
In general what is the behavior if I throw an exception. It will print the logs in the console right? Instead, I want just one line message. How this could be done using throw? If I catch, I can use exception.getmessage. If I throw, the entire trace is getting printed.
– Shakthi
Nov 10 at 16:10
Without knowing your setup we can’t tell. No, a program only produces a log if the code explicitly does so, and the only things that go into the log are those that the code writes into it.
– Ole V.V.
Nov 11 at 7:06
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
What is the best practice to throw the error message?
As soon as I throw the exception, the exception has been traced in the errorlog.log file. I have more custom exception. If I throw these exceptions, for all the incorrect attempt, it will be traced in the logfile and it bugs the file and increasing the log file size.
what is the good way of doing this? Is it mandatory in java that we have to do the programming like this?
I want most of my custom messages like single line of error and very critical error should be thrown with complete error trace.
Need suggestion on error handling and tracing the log.
java exception error-handling
What is the best practice to throw the error message?
As soon as I throw the exception, the exception has been traced in the errorlog.log file. I have more custom exception. If I throw these exceptions, for all the incorrect attempt, it will be traced in the logfile and it bugs the file and increasing the log file size.
what is the good way of doing this? Is it mandatory in java that we have to do the programming like this?
I want most of my custom messages like single line of error and very critical error should be thrown with complete error trace.
Need suggestion on error handling and tracing the log.
java exception error-handling
java exception error-handling
asked Nov 10 at 14:09
Shakthi
143213
143213
3
You should look into the logging frameworks likeslf4j
orlog4j
. They offer different logging levels, which exceptions might trigger. A severe message would only be logged for very serious exceptions.
– Tim Biegeleisen
Nov 10 at 14:11
It’s not a rule of life that every exception thrown is logged. I’d rather say it’s bad practice to so indiscriminately. I don’t know why your exceptions are, but it must come from a mechanism that is specific to your system.
– Ole V.V.
Nov 10 at 14:47
In general what is the behavior if I throw an exception. It will print the logs in the console right? Instead, I want just one line message. How this could be done using throw? If I catch, I can use exception.getmessage. If I throw, the entire trace is getting printed.
– Shakthi
Nov 10 at 16:10
Without knowing your setup we can’t tell. No, a program only produces a log if the code explicitly does so, and the only things that go into the log are those that the code writes into it.
– Ole V.V.
Nov 11 at 7:06
add a comment |
3
You should look into the logging frameworks likeslf4j
orlog4j
. They offer different logging levels, which exceptions might trigger. A severe message would only be logged for very serious exceptions.
– Tim Biegeleisen
Nov 10 at 14:11
It’s not a rule of life that every exception thrown is logged. I’d rather say it’s bad practice to so indiscriminately. I don’t know why your exceptions are, but it must come from a mechanism that is specific to your system.
– Ole V.V.
Nov 10 at 14:47
In general what is the behavior if I throw an exception. It will print the logs in the console right? Instead, I want just one line message. How this could be done using throw? If I catch, I can use exception.getmessage. If I throw, the entire trace is getting printed.
– Shakthi
Nov 10 at 16:10
Without knowing your setup we can’t tell. No, a program only produces a log if the code explicitly does so, and the only things that go into the log are those that the code writes into it.
– Ole V.V.
Nov 11 at 7:06
3
3
You should look into the logging frameworks like
slf4j
or log4j
. They offer different logging levels, which exceptions might trigger. A severe message would only be logged for very serious exceptions.– Tim Biegeleisen
Nov 10 at 14:11
You should look into the logging frameworks like
slf4j
or log4j
. They offer different logging levels, which exceptions might trigger. A severe message would only be logged for very serious exceptions.– Tim Biegeleisen
Nov 10 at 14:11
It’s not a rule of life that every exception thrown is logged. I’d rather say it’s bad practice to so indiscriminately. I don’t know why your exceptions are, but it must come from a mechanism that is specific to your system.
– Ole V.V.
Nov 10 at 14:47
It’s not a rule of life that every exception thrown is logged. I’d rather say it’s bad practice to so indiscriminately. I don’t know why your exceptions are, but it must come from a mechanism that is specific to your system.
– Ole V.V.
Nov 10 at 14:47
In general what is the behavior if I throw an exception. It will print the logs in the console right? Instead, I want just one line message. How this could be done using throw? If I catch, I can use exception.getmessage. If I throw, the entire trace is getting printed.
– Shakthi
Nov 10 at 16:10
In general what is the behavior if I throw an exception. It will print the logs in the console right? Instead, I want just one line message. How this could be done using throw? If I catch, I can use exception.getmessage. If I throw, the entire trace is getting printed.
– Shakthi
Nov 10 at 16:10
Without knowing your setup we can’t tell. No, a program only produces a log if the code explicitly does so, and the only things that go into the log are those that the code writes into it.
– Ole V.V.
Nov 11 at 7:06
Without knowing your setup we can’t tell. No, a program only produces a log if the code explicitly does so, and the only things that go into the log are those that the code writes into it.
– Ole V.V.
Nov 11 at 7:06
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239780%2fjava-throwing-exception-best-practise%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
You should look into the logging frameworks like
slf4j
orlog4j
. They offer different logging levels, which exceptions might trigger. A severe message would only be logged for very serious exceptions.– Tim Biegeleisen
Nov 10 at 14:11
It’s not a rule of life that every exception thrown is logged. I’d rather say it’s bad practice to so indiscriminately. I don’t know why your exceptions are, but it must come from a mechanism that is specific to your system.
– Ole V.V.
Nov 10 at 14:47
In general what is the behavior if I throw an exception. It will print the logs in the console right? Instead, I want just one line message. How this could be done using throw? If I catch, I can use exception.getmessage. If I throw, the entire trace is getting printed.
– Shakthi
Nov 10 at 16:10
Without knowing your setup we can’t tell. No, a program only produces a log if the code explicitly does so, and the only things that go into the log are those that the code writes into it.
– Ole V.V.
Nov 11 at 7:06