Tagged Questions
1
vote
6answers
62 views
Should you catch all exceptions in your main method
Is it correct to catch everything into the main? If not, why?
public static void main(String[] args) {
try {
// A lot
// of
// calls
} catch (Exception e) {
...
2
votes
3answers
104 views
C# throw statement redundant?
I have a code that looks like this (sorry for the Java bracket style):
class SomeClass {
public static void doSomethingRisky() {
try {
SomeRiskyFunction();
} catch ...
8
votes
4answers
126 views
Having a try-catch block, should you place ALL statements in it or just the unsafe one?
Suppose save throws and i is used only for save. Are the following code fragments the same? Please consider sematics, performance and other aspects.
void bob(){
int i = calculate();
try {
...
0
votes
2answers
22 views
Struts2 customExceptionMappingInterceptor
I already searched here and on internet but I couldn't find a solution for my problem.
I would like to use my custom exceptionHandler to intercept all the java exceptions and to treat them in a ...
0
votes
1answer
24 views
Launch a pdf file from java
I am trying to open a pdf file from the following code.
try {
String currentDir = System.getProperty("user.dir");
currentDir = currentDir+"/Report.pdf";
...
4
votes
3answers
140 views
Exception Handling guideline- Python vs Java
I am original Java developer, for me, checked Exception in Java is obviously/easy enough for me to decide to catch or throw it to the caller to handle later. Then it comes Python, there is no checked ...
-1
votes
2answers
69 views
Why return null after catching an Exception? [closed]
I've encountered some code which is catching RestClientException and then returning null. I think this is bad practice ? Why would a developer (who has since moved on) do this ? The method in which ...
0
votes
4answers
47 views
removing last element in arraylist exception [closed]
at first I was having issues removing an element in an arraylist if it was the only one on the list, which i over came by simply setting all the varibles of the element to null/0 if it is the only ...
6
votes
2answers
85 views
Java Exception Classes
I am new to java and I was looking at exception handling. When we catch java exceptions, we declare and use an Object of the Exception class without initializing it i.e., catch(NullPointerException e) ...
1
vote
1answer
41 views
Find Exception type
If I have the following code:
try {
//some offensive code
} catch (Exception e) {
String type = //get type of e
Assert.fail(type + " thrown.");
}
Is there a way I can get the type ...
2
votes
5answers
94 views
FileNotFoundException in java
Im developing a simple android application which needs a text file access! Im getting filenotfoundexception eventhough i specified the absolute path of the file in File constructor.. My code is
`File ...
2
votes
3answers
44 views
Which exception to throw for invalid input which is valid from client perspective
I am writing code to find and intersection of 2 lines.
When slopes of the lines are equal they dont intersect. But on the other hand an input with slopes of equal value is completely valid.
public ...
0
votes
1answer
36 views
Using Anonymous thread for catching Exceptions
I asked around regarding catching checked exceptions in the context of a thread; the accepted answer was to use Callables and Futures.
But I realized that I can simply wrap the "working" method with ...
-2
votes
1answer
85 views
Try/Catch statement not working [closed]
I am having some trouble with this particular try/catch block. It should work, but every time I enter a letter, I still get a NumberFormatException. Can anyone identify the problem with this code? ...
0
votes
1answer
66 views
Exception causing Log.e() to be skipped
I have the following code that I'm trying to debug:
public Cursor getUpdateTimestamps() {
Cursor timestamps;
try {
// int j = 3 / 0; // This will throw a divide-by-zero exception
...