When XML schema validation fails .Net throws some exception. Based on parsing this exception I know how to do some stuff. The problem is that this exception is localized, e.g. on a Japanese machine it is in Japanese.
I do not want to build my application so it will parse every error in any language.
I am an add-in to some other system so I do not want to change the locale (unless something is totally clean).
Any ideas?
Related
My team is currently using Boomlagoon's JSON library. The problem is that we ship the game with "fast but no exceptions" turned on (like most recommend to do), so if there is a JSON error the app will crash. The JSON string we are deserializing is from a server, which is why it is not necessarily trustworthy. Simply wrapping JSONObject.Parse in a try/catch would actually by sufficient for our needs (it is fine to ignore a broken response, and all we care about is not CRASHING). However, since exceptions are turned off, this can no longer be relied upon. The only solution we can think of is to write a JSON-verifier (e.g. if (JSON.verify(string)) JSONObject.Parse(string) ), which starts to just look like writing our own JSON parse at that point. Is there an alternative strategy or perhaps a JSON library out there that uses error objects instead of exceptions?
If not mistaken: http://james.newtonking.com/json would do the validating,
it is open source and written in c# wrap it in a plugin and throw in a plugin folder in unity and you will have a validator.
I am using Enterprise Library's DAAB to access a database, both with ExecuteReader and ExecuteNonQuery. The problem is that these methods do not have exceptions thrown documented... How can I, then, know which exceptions should I catch?
I agree with WebTurner, I'm guessing a good place to start would be which database your connecting to, so if an ms sql database I'm guessing a couple of (perhaps many) exceptions would be:
SqlException
InvalidOperationException
http://msdn.microsoft.com/en-us/library/9kcbe65k.aspx
EDIT:
I just came across this: How can I determine which exceptions can be thrown by a given method?
Which looks liek it uses reflection to help uncover a list of exceptions that are thrown.
The problem is that there are many exceptions that will be thrown at a lower level than the enterprise library, and it would be impossible for EL to document all of these.
I suggest you use the exception handling and logging blocks to catch and log all exceptions. You can then see which ones occur and adapt the configuration of the exception handler or add new code to handle the specific execptions.
In exception handling, in a multi-language app, is it bad to store English in the code (strings in classes)? Is it better to use just error codes and document these? I saw a best practise somewhere that your code should not have strings which are exception messages etc (although perhaps they can be refactored out and converted to other languages at will).
Thanks
Why don't you place urls instead of error codes. This could be in the form of: http://myapp.com/help/error/434hb4b3.html&language=english
This way you are free to:
Modify the help on the error message later without having to update the software
Easily add languages
Make the help for this error message a wiki so the users can modify the page and include workarounds etc.
You don't mention the language/framework you are developing in, however...
Another solution would be to put your error descriptions into localised resource files. This way everything ships together and customer not have to have an internet connection access error details.
I'm interested in the different ways warnings and errors are (and could be) handled in programming languages. As far as I know, the only language-level error/warning functionality are the following:
compiler errors/warnings (which can be created by programmers using compiler commands, usually compiler specific)
console errors that can be redirected to a file - eg stderr in C-like langauges
throwable exception objects using explicit exception classes (like in java)
simple string exceptions (like in php and javascript, e.g. throw("Dental error");
Are there other structures I haven't mentioned? What other kind of language-level functionality do you think should exist / could be useful?
My first through is to use exception-like structures for both, where an uncaught warning would be logged in a flat file (or brought up at compile-time if the compiler can prove it will happen). I can't decide whether its a good idea to force methods to explicitly handle exceptions, or if they should be allowed to "bubble up".
What error and warning handling structures and ideas are there out there?
Perhaps break to debugger?
What are the best practices for exceptions over remote methods?
I'm sure that you need to handle all exceptions at the level of a remote method implementation, because you need to log it on the server side. But what should you do afterwards?
Should you wrap the exception in a RemoteException (java) and throw it to the client? This would mean that the client would have to import all exceptions that could be thrown. Would it be better to throw a new custom exception with fewer details? Because the client won't need to know all the details of what went wrong. What should you log on the client? I've even heard of using return codes(for efficiency maybe?) to tell the caller about what happened.
The important thing to keep in mind, is that the client must be informed of what went wrong. A generic answer of "Something failed" or no notification at all is unacceptable. And what about runtime (unchecked) exceptions?
It seems like you want to be able to differentiate if the failure was due to a system failure (e.g. a service or machine is down) or a business logic failure (e.g. the user does not exist).
I'd recommend wrapping all system exceptions from the RMI call with your own custom exception. You can still maintain the information in the exception by passing it to your custom exception as the cause (this is possible in Java, not sure about other languages). That way client only need to know how to handle the one exception in the cause of system failure. Whether this custom exception is checked or runtime is up for debate (probably depends on your project standards). I would definitely log this type of failure.
Business type failures can be represented as either a separate exception or some type of default (or null) response object. I would attempt to recover (i.e. take some alternative action) from this type of failure and log only if the recovery fails.
In past projects we'd catch all service layer (tier) exceptions at the very top of the layer, passing the application specific error codes/information to the UI via DTO's/VO's. It's a simple approach in that there's an established pattern of all error handling happening in the same place for each service instead of scattered about the service and UI layers.
Then all the UI has to do is inspect the DTO/VO for a flag (hasError?) and display the error message(s), it doesn't have to know nor care what the actual exception was.
I would always log the exception within my application (at the server side as defined in your question).
I would then throw an exception, to be caught by the client. If the caller could take corrective action to prevent the exception then I would ensure that the exception contained this information (e.g. DateTime argName must not be in the past). If the error was caused by some outage of a third party system then I might pass this information up the call stack to the caller.
If, however, the exception was essentially caused by a bug in my system then I would structure my exception handling such that a non-informative exception message (e.g. General failure) was used.
Here's what I did. Every Remote Method implementation catches all Exceptions on the server side and logs them. Then they are wrapped in a Custom Exception, which will contain a description of the problem. This description must be useful to the client, so it won't contain all the details of the caught Exception, because the client doesn't need them. They have already been logged on the server side. Now, on the client, these Exceptions can be handled how the user wishes.
Why I chose using Exceptions and not return codes is because of one very important drawback of return codes: you can't throw them to higher levels without some effort. This means you have to check for an error right after the call and handle it there. But this may not be what I want.