Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 20065

An exception is an occurrence in an application process that requires deviation from the program's normal flow.

4 votes
Accepted

Recommendations for adding exceptions messages to code

If we follow recommendations from that book, you could : break that huge if tree into smaller chunks of code put throwing exceptions into private methods at the end of files And that would be the solution …
BЈовић's user avatar
  • 14.1k
40 votes

if/else statements or exceptions

The usual way of error handling is this: If you can solve the problem locally, then use the if statement (or if the function throw an exception, handle that exception). If you can not solve the probl …
BЈовић's user avatar
  • 14.1k
43 votes

Are exceptions an OOP concept?

Exceptions and OOP are unrelated. Exceptions handling is a mechanism to handle errors. … Comparing C (not really OOP language, possible to somehow emulate exceptions in C) and C++ (OOP, supports exceptions), nothing prevents C's standard committee from adding exceptions handling to C, it will …
BЈовић's user avatar
  • 14.1k
2 votes

Should we only catch in exceptional circumstances?

I think you do not understand how the exceptions are used. What is important to understand is : you can not ignore exceptions. In a normal program execution, an exception must not occur. … Performance wise, program with the use of exceptions will be better or same then the program without exceptions, because of zero-cost mechanism. …
BЈовић's user avatar
  • 14.1k
8 votes

should I throw exception from constructor?

I know I can throw exception from constructor in PHP but should I do it? That is the only sane way to inform that the object construction failed.
BЈовић's user avatar
  • 14.1k
2 votes

What's the reason exceptions are heavily used in managed (C# and Java) languages but not in ...

a lot of C++ projects don't allow exceptions and deny them in coding guidelines I would say ignorance. … By only adding exceptions to a c program (and nothing else from c++), the complexity would be greatly reduced. …
BЈовић's user avatar
  • 14.1k
1 vote

Augment a thrown exception with some contextual information

If you use boost exceptions, then you can use their diagnostics. …
BЈовић's user avatar
  • 14.1k
78 votes

Is throwing an exception an anti-pattern here?

Yes, your colleague is right: that is bad code. If an error can be handled locally, then it should be handled immediately. An exception should not be thrown and then handled immediately. This is much …
BЈовић's user avatar
  • 14.1k