Search Results

Search found 2244 results on 90 pages for 'exceptions'.

Page 2/90 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Where to handle fatal exceptions

    - by Stephen Swensen
    I am considering a design where all fatal exceptions will be handled using a custom UncaughtExceptionHandler in a Swing application. This will include unanticipated RuntimeExceptions but also custom exceptions which are thrown when critical resources are unavailable or otherwise fail (e.g. a settings file not found, or a server communication error). The UncaughtExceptionHandler will do different things depending on the specific custom exception (and one thing for all the unanticipated), but in all cases the application will show the user an error message and exit. The alternative would be to keep the UncaughtExceptionHandler for all unanticipated exceptions, but handle all other fatal scenarios close to their origin. Is the design I'm considering sound, or should I use the alternative?

    Read the article

  • CLR 4.0: Corrupted State Exceptions

    - by Scott Dorman
    Corrupted state exceptions are designed to help you have fewer bugs in your code by making it harder to make common mistakes around exception handling. A very common pattern is code like this: public void FileSave(String name) { try { FileStream fs = new FileStream(name, FileMode.Create); } catch (Exception e) { MessageBox.Show("File Open Error"); throw new Exception(IOException); } The standard recommendation is not to catch System.Exception but rather catch the more specific exceptions (in this case, IOException). While this is a somewhat contrived example, what would happen if Exception were really an AccessViolationException or some other exception indicating that the process state has been corrupted? What you really want to do is get out fast before persistent data is corrupted or more work is lost. To help solve this problem and minimize the chance that you will catch exceptions like this, CLR 4.0 introduces Corrupted State Exceptions, which cannot be caught by normal catch statements. There are still places where you do want to catch these types of exceptions, particularly in your application’s “main” function or when you are loading add-ins.  There are also rare circumstances when you know code that throws an exception isn’t dangerous, such as when calling native code. In order to support these scenarios, a new HandleProcessCorruptedStateExceptions attribute has been added. This attribute is added to the function that catches these exceptions. There is also a process wide compatibility switch named legacyCorruptedStateExceptionsPolicy which when set to true will cause the code to operate under the older exception handling behavior. Technorati Tags: CLR 4.0, .NET 4.0, Exception Handling, Corrupted State Exceptions

    Read the article

  • I've been told that Exceptions should only be used in exceptional cases. How do I know if my case is exceptional?

    - by tieTYT
    My specific case here is that the user can pass in a string into the application, the application parses it and assigns it to structured objects. Sometimes the user may type in something invalid. For example, their input may describe a person but they may say their age is "apple". Correct behavior in that case is roll back the transaction and to tell the user an error occurred and they'll have to try again. There may be a requirement to report on every error we can find in the input, not just the first. In this case, I argued we should throw an exception. He disagreed, saying, "Exceptions should be exceptional: It's expected that the user may input invalid data, so this isn't an exceptional case" I didn't really know how to argue that point, because by definition of the word, he seems to be right. But, it's my understanding that this is why Exceptions were invented in the first place. It used to be you had to inspect the result to see if an error occurred. If you failed to check, bad things could happen without you noticing. Without exceptions every level of the stack needs to check the result of the methods they call and if a programmer forgets to check in one of these levels, the code could accidentally proceed and save invalid data (for example). Seems more error prone that way. Anyway, feel free to correct anything I've said here. My main question is if someone says Exceptions should be exceptional, how do I know if my case is exceptional?

    Read the article

  • Can I enable/disable breaking on Exceptions programatically?

    - by Tony Lambert
    I want to be able to break on Exceptions when debugging... like in Visual Studio 2008's Menu Debug/Exception Dialog, except my program has many valid exceptions before I get to the bit I wish to debug. So instead of manually enabling and disabling it using the dialog every time is it possible to do it automatically with a #pragma or some other method so it only happens in a specific piece of code?

    Read the article

  • C# Checked exceptions

    - by Ryan B.
    One feature I really liked in Java that isn't in C# is checked exceptions, Is there any way to simulate or turn on checked exceptions in Visual Studio? Yes I know a lot of people dislike them, but I find they can be helpful.

    Read the article

  • Performances des exceptions C++, un article de Vlad Lazarenko traduit par LittleWhite

    Bonjour à tous, Je vous présente une nouvelle traduction de l'article de Vlad Lazarenko discutant des performances des exceptions en C++. Souvent, lorsque l'on écrit du code, on se demande l'impact des exceptions sur les performances de notre programme. Cet article apporte donc des éléments de réponse détaillés à cette question. Performances des exceptions C++ Avez-vous évité d'utiliser des exceptions pour préserver les performances ? Dans quel cas avez vo...

    Read the article

  • C++ custom exceptions: run time performance and passing exceptions from C++ to C

    - by skyeagle
    I am writing a custom C++ exception class (so I can pass exceptions occuring in C++ to another language via a C API). My initial plan of attack was to proceed as follows: //C++ myClass { public: myClass(); ~myClass(); void foo() // throws myException int foo(const int i, const bool b) // throws myException } * myClassPtr; // C API #ifdef __cplusplus extern "C" { #endif myClassPtr MyClass_New(); void MyClass_Destroy(myClassPtr p); void MyClass_Foo(myClassPtr p); int MyClass_FooBar(myClassPtr p, int i, bool b); #ifdef __cplusplus }; #endif I need a way to be able to pass exceptions thrown in the C++ code to the C side. The information I want to pass to the C side is the following: (a). What (b). Where (c). Simple Stack Trace (just the sequence of error messages in order they occured, no debugging info etc) I want to modify my C API, so that the API functions take a pointer to a struct ExceptionInfo, which will contain any exception info (if an exception occured) before consuming the results of the invocation. This raises two questions: Question 1 1. Implementation of each of the C++ methods exposed in the C API needs to be enclosed in a try/catch statement. The performance implications for this seem quite serious (according to this article): "It is a mistake (with high runtime cost) to use C++ exception handling for events that occur frequently, or for events that are handled near the point of detection." At the same time, I remember reading somewhere in my C++ days, that all though exception handling is expensive, it only becmes expensive when an exception actually occurs. So, which is correct?. what to do?. Is there an alternative way that I can trap errors safely and pass the resulting error info to the C API?. Or is this a minor consideration (the article after all, is quite old, and hardware have improved a bit since then). Question 2 I wuld like to modify the exception class given in that article, so that it contains a simple stack trace, and I need some help doing that. Again, in order to make the exception class 'lightweight', I think its a good idea not to include any STL classes, like string or vector (good idea/bad idea?). Which potentially leaves me with a fixed length C string (char*) which will be stack allocated. So I can maybe just keep appending messages (delimted by a unique separator [up to maximum length of buffer])... Its been a while since I did any serious C++ coding, and I will be grateful for the help. BTW, this is what I have come up with so far (I am intentionally, not deriving from std::exception because of the performance reasons mentioned in the article, and I am instead, throwing an integral exception (based on an exception enumeration): class fast_exception { public: fast_exception(int what, char const* file=0, int line=0) : what_(what), line_(line), file_(file) {/*empty*/} int what() const { return what_; } int line() const { return line_; } char const* file() const { return file_; } private: int what_; int line_; char const[MAX_BUFFER_SIZE] file_; }

    Read the article

  • What's the best way to manage error logging for exceptions?

    - by Peter Boughton
    Introduction If an error occurs on a website or system, it is of course useful to log it, and show the user a polite message with a reference code for the error. And if you have lots of systems, you don't want this information dotted around - it is good to have a single centralised place for it. At the simplest level, all that's needed is an incrementing id and a serialized dump of the error details. (And possibly the "centralised place" being an email inbox.) At the other end of the spectrum is perhaps a fully normalised database that also allows you to press a button and see a graph of errors per day, or identifying what the most common type of error on system X is, whether server A has more database connection errors than server B, and so on. What I'm referring to here is logging code-level errors/exceptions by a remote system - not "human-based" issue tracking, such as done with Jira,Trac,etc. Questions I'm looking for thoughts from developers who have used this type of system, specifically with regards to: What are essential features you couldn't do without? What are good to have features that really save you time? What features might seem a good idea, but aren't actually that useful? For example, I'd say a "show duplicates" function that identifies multiple occurrence of an error (without worrying about 'unimportant' details that might differ) is pretty essential. A button to "create an issue in [Jira/etc] for this error" sounds like a good time-saver. Just to re-iterate, what I'm after is practical experiences from people that have used such systems, preferably backed-up with why a feature is awesome/terrible. (If you're going to theorise anyway, at the very least mark your answer as such.)

    Read the article

  • What is the correct way to unit test areas around exceptions

    - by Codek
    Hi, Looking at our code coverage of our unit tests we're quite high. But the last few % is tricky because a lot of them are catching things like database exceptions - which in normal circumstances just dont happen. For example the code prevents fields being too long etc, so the only possible database exceptions are if the DB is broken/down, or if the schema is changed under our feet. So is the only way to Mock the objects such that the exception can be thrown? That seems a little bit pointless. Perhaps it's better to just accept not getting 100% code coverage? Thanks, Dan

    Read the article

  • where to store web service exceptions?

    - by ICoder
    Hello all, I am working on building a web service (using c#) and this web service will use MS Sql server database. Now, I am trying to build an (exceptions log system) for this web service. Simply, I want to save every exception on the web service for future use (bug tracing), so, where is the best place to save these exceptions? Is it good idea to save it in the database? What if the exception is in the connection to the database itself? I really appreciate your help and your ideas. Thanks

    Read the article

  • How To Deal With Exceptions In Large Code Bases

    - by peter
    Hi All, I have a large C# code base. It seems quite buggy at times, and I was wondering if there is a quick way to improve finding and diagnosing issues that are occuring on client PCs. The most pressing issue is that exceptions occur in the software, are caught, and even reported through to me. The problem is that by the time they are caught the original cause of the exception is lost. I.e. If an exception was caught in a specific method, but that method calls 20 other methods, and those methods each call 20 other methods. You get the picture, a null reference exception is impossible to figure out, especially if it occured on a client machine. I have currently found some places where I think errors are more likely to occur and wrapped these directly in their own try catch blocks. Is that the only solution? I could be here a long time. I don't care that the exception will bring down the current process (it is just a thread anyway - not the main application), but I care that the exceptions come back and don't help with troubleshooting. Any ideas? I am well aware that I am probably asking a question which sounds silly, and may not have a straightforward answer. All the same some discussion would be good.

    Read the article

  • C++ exceptions binary compatibility

    - by aaa
    hi. my project uses 2 different C++ compilers, g++ and nvcc (cuda compiler). I have noticed exception thrown from nvcc object files are not caught in g++ object files. are C++ exceptions supposed to be binary compatible in the same machine? what can cause such behavior?

    Read the article

  • When to throw exceptions?

    - by FRKT
    Exceptions are wonderful things, but I sometimes worry that I throw too many. Consider this example: Class User { public function User(user){ // Query database for user data if(!user) throw new ExistenceException('User not found'); } } I'd argue that it makes as much sense to simply return false (or set all user data to false in this case), rather than throwing an exception. Which do you prefer?

    Read the article

  • How to differentiate between Programmer and JVM Exceptions

    - by Haxed
    As the title suggests, how can I tell a JVM thrown exception from a Programmatically(does this mean, thrown by a programmer or the program) thrown exception ? JVM Exceptions 1) ArrayIndexOutOfBoundsException 2) ClassCastException 3) NullPointerException Programmatically thrown 1) NumberFormatException 2) AssertionError Many Thanks

    Read the article

  • How to deferentiate between Programmer and JVM Exceptions

    - by Haxed
    As the title suggests, how can I tell a JVM thrown exception from a Programmatically(does this mean, thrown by a programmer or the program) thrown exception ? JVM Exceptions 1) ArrayIndexOutOfBoundsException 2) ClassCastException 3) NullPointerException Programmatically thrown 1) NumberFormatException 2) AssertionError Many Thanks

    Read the article

  • Best method in PHP for the Error Handling ? Convert all PHP errors (warnings notices etc) to exceptions?

    - by user1179459
    What is the best method in PHP for the Error Handling ? is there a way in PHP to Convert all PHP errors (warnings notices etc) to exceptions ? what the best way/practise to error handling ? again: if we overuse exceptions (i.e. try/catch) in many situations, i think application will be halted unnecessary. for a simple error checking we can use return false; but it may be cluttering the coding with many if else conditions. what do you guys suggest ?

    Read the article

  • Handle .NET exceptions within Classic ASP pages

    - by Tyler
    Hi All, I am making MSSQL stored procedure CLR calls from ASP pages. When an exception occurs, it is logged and then rethrown. In this scenario I need to be able to handle the exception (if possible) in the ASP page. Note that I cannot move away from classic ASP in this instance; I am stuck within a legacy system for this project. Please let me know if you know of a way to handle the exceptions in classic ASP. I appreciate the help! Thanks, Tyler

    Read the article

  • Exception design: Custom exceptions reading data from file?

    - by User
    I have a method that reads data from a comma separated text file and constructs a list of entity objects, let's say customers. So it reads for example, Name Age Weight Then I take these data objects and pass them to a business layer that saves them to a database. Now the data in this file might be invalid, so I'm trying to figure out the best error handling design. For example, the text file might have character data in the Age field. Now my question is, should I throw an exception such as InvalidAgeException from the method reading the file data? And suppose there is length restriction on the Name field, so if the length is greater than max characters do I throw a NameTooLongException or just an InvalidNameException, or do I just accept it and wait until the business layer gets a hold of it and throw exceptions from there? (If you can point me to a good resource that would be good too)

    Read the article

  • How to handle sharepoint web services exceptions

    - by Royson
    Hi, I have developed an application of share point. I am using web services for that. the problem is that while working with my app sometimes i get some exceptions. like, Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown. Stack Strace :: at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at ......... my methods From this exception i cannot understand the main problem. While developing i can debug the code, but now my application is getting launched..i can get error log file from my client which contains this type of excetions. But how to catch exact error.??? Thanks.

    Read the article

  • nUnit Assert.That(method,Throws.Exception) not catching exceptions

    - by JasonM
    Hi Everyone, Can someone tell me why this unit test that checks for exceptions fails? Obviously my real test is checking other code but I'm using Int32.Parse to show the issue. [Test] public void MyTest() { Assert.That(Int32.Parse("abc"), Throws.Exception.TypeOf<FormatException>()); } The test fails, giving this error. Obviously I'm trying to test for this exception and I think I'm missing something in my syntax. Error 1 TestCase '.MyTest' failed: System.FormatException : Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Int32.Parse(String s) based on the documentation at Throws Constraint (NUnit 2.5)

    Read the article

  • PHP Exceptions in Classes

    - by mike condiff
    I'm writing a web application (PHP) for my friend and have decided to use my limited OOP training from Java. My question is what is the best way to note in my class/application that specific critical things failed without actually breaking my page. Currently my problem is I have an Object "SummerCamper" which takes a camper_id as it's argument to load all of the necessary data into the object from the database. Say someone specifies a camper_id in the querystring that does not exist, I pass it to my objects constructor and the load fails. Currently I don't see a way for me to just return false from the constructor. I have read I could possibly do this with Exceptions, throwing an exception if no records are found in the database or if some sort of validation fails on input of the camper_id from the application etc. However, I have not really found a great way to alert my program that the Object Load has failed. I tried returning false from within the CATCH but the Object still persists in my php page. I do understand I could put a variable $is_valid = false if the load fails and then check the Object using a get method but I think there may be better ways. What is the best way of achieving the essential termination of an object if a load fails? Should I load data into the object from outside the constructor? Is there some osrt of design pattern that I should look into? Any help would be appreciated.

    Read the article

  • Exercices Java : Exercez-vous au traitement des exceptions, par Sébastien Estienne

    Ce dixième chapitre aborde le traitement des exceptions. Le premier exercice s'intéresse à la saisie d'un entier par un utilisateur dans une boîte de dialogue. Le deuxième exercice concerne la division par zéro illustrant la création de nouvelles exceptions. Le troisième exercice montre le fonctionnement des exceptions. Le dernier exercice porte sur la saisie de longueurs appliquée à la saisie de ses dimensions.

    Read the article

  • Catch Multiple Custom Exceptions? - C++

    - by Alex
    Hi all, I'm a student in my first C++ programming class, and I'm working on a project where we have to create multiple custom exception classes, and then in one of our event handlers, use a try/catch block to handle them appropriately. My question is: How do I catch my multiple custom exceptions in my try/catch block? GetMessage() is a custom method in my exception classes that returns the exception explanation as a std::string. Below I've included all the relevant code from my project. Thanks for your help! try/catch block // This is in one of my event handlers, newEnd is a wxTextCtrl try { first.ValidateData(); newEndT = first.ComputeEndTime(); *newEnd << newEndT; } catch (// don't know what do to here) { wxMessageBox(_(e.GetMessage()), _("Something Went Wrong!"), wxOK | wxICON_INFORMATION, this);; } ValidateData() Method void Time::ValidateData() { int startHours, startMins, endHours, endMins; startHours = startTime / MINUTES_TO_HOURS; startMins = startTime % MINUTES_TO_HOURS; endHours = endTime / MINUTES_TO_HOURS; endMins = endTime % MINUTES_TO_HOURS; if (!(startHours <= HOURS_MAX && startHours >= HOURS_MIN)) throw new HourOutOfRangeException("Beginning Time Hour Out of Range!"); if (!(endHours <= HOURS_MAX && endHours >= HOURS_MIN)) throw new HourOutOfRangeException("Ending Time Hour Out of Range!"); if (!(startMins <= MINUTE_MAX && startMins >= MINUTE_MIN)) throw new MinuteOutOfRangeException("Starting Time Minute Out of Range!"); if (!(endMins <= MINUTE_MAX && endMins >= MINUTE_MIN)) throw new MinuteOutOfRangeException("Ending Time Minute Out of Range!"); if(!(timeDifference <= P_MAX && timeDifference >= P_MIN)) throw new PercentageOutOfRangeException("Percentage Change Out of Range!"); if (!(startTime < endTime)) throw new StartEndException("Start Time Cannot Be Less Than End Time!"); } Just one of my custom exception classes, the others have the same structure as this one class HourOutOfRangeException { public: // param constructor // initializes message to passed paramater // preconditions - param will be a string // postconditions - message will be initialized // params a string // no return type HourOutOfRangeException(string pMessage) : message(pMessage) {} // GetMessage is getter for var message // params none // preconditions - none // postconditions - none // returns string string GetMessage() { return message; } // destructor ~HourOutOfRangeException() {} private: string message; };

    Read the article

  • Exceptions confusion

    - by Misiur
    Hi there. I'm trying to build site using OOP in PHP. Everyone is talking about Singleton, hermetization, MVC, and using exceptions. So I've tried to do it like this: Class building whole site: class Core { public $is_core; public $theme; private $db; public $language; private $info; static private $instance; public function __construct($lang = 'eng', $theme = 'default') { if(!self::$instance) { try { $this->db = new sdb(DB_TYPE.':host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASS); } catch(PDOException $e) { throw new CoreException($e->getMessage()); } try { $this->language = new Language($lang); } catch(LangException $e) { throw new CoreException($e->getMessage()); } try { $this->theme = new Theme($theme); } catch(ThemeException $e) { throw new CoreException($e->getMessage()); } } return self::$instance; } public function getSite($what) { return $this->language->getLang(); } private function __clone() { } } Class managing themes class Theme { private $theme; public function __construct($name = 'default') { if(!is_dir("themes/$name")) { throw new ThemeException("Unable to load theme $name"); } else { $this->theme = $name; } } public function getTheme() { return $this->theme; } public function display($part) { if(!is_file("themes/$this->theme/$part.php")) { throw new ThemeException("Unable to load theme part: themes/$this->theme/$part.php"); } else { return 'So far so good'; } } } And usage: error_reporting(E_ALL); require_once('config.php'); require_once('functions.php'); try { $core = new Core(); } catch(CoreException $e) { echo 'Core Exception: '.$e->getMessage(); } echo $core->theme->getTheme(); echo "<br />"; echo $core->language->getLang(); try { $core->theme->display('footer'); } catch(ThemeException $e) { echo $e->getMessage(); } I don't like those exception handlers - i don't want to catch them like some pokemons... I want to use things simple: $core-theme-display('footer'); And if something is wrong, and debug mode is enabled, then aplication show error. What should i do?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >