Top 4 Java exceptions Raygun can help fix

來源:互聯網
上載者:User

標籤:

 

Top 4 Java exceptions Raygun can help fixProvider RelatedResourceTech Stuff Callum Gavin April 20, 2015 Leave a comment

There are a bunch of Java exceptions that are common to all code bases, and frequently occur at both compile time when implementing, and runtime when your application is in the wild. This last case is crucial to have visibility around – most developers may use a logging framework, or perhaps a hand-rolled notification system. The advantage of using a real error tracking service is huge. Here are some of the most common Java exceptions, and how Raygun can capture these at runtime and help you find the source of the bug, leading to reliable software and happy end users.

NullPointerException

Tony Hoare’s billion-dollar mistake of including ‘null’ in a modification to the Algol language must still be taken into account when dealing with the type system in Java (you will of course note that it’s a legit failure state, which can be handled in safer ways in languages like Rust). The act of accessing an uninitialized variable, or one that has been deliberately set to null, blows up strongly-typed code at runtime as the type system can’t provide any guarantees for the object (by design). Knowing when your code attempts to use null variables is crucial. If you’re in a web context, frequently a third-party API may return some error state in response to a request, and the variables which would have otherwise been set would be null.


(I know – it’s Knuth, not Hoare, but close enough. The hat sells it.)

Seriously though, Raygun will capture every instance of your code attempting to use null objects, and report the stack trace so you can pinpoint the issue. The Raygun4Java provider also allows you to set custom data, so you can provide the state of relevant variables, allowing you to easily diagnose NullPointerExceptions on your production hardware from your local machine.

IOException

This exception type (and others in its family) can be thrown when invalid file access occurs, which is most likely to occur when implementing a local application when debugging is easier. Networking errors can also result in this exception being thrown, which is more critical when this happens in production web applications or services.

It is particularly interesting how often connections can fall down at the network layer – for instance, database query timeouts. These can be quite frequent, especially if your code is running in a public cloud with noisy neighbours, or in general if resource contention is a factor. Raygun will capture instances of these exceptions, giving you insights as to how often these are occurring over time, which would be very difficult to see from view log files.

Concurrent (threading) exceptions

Exceptions like InterruptedException are raised when your thread receives an interrupt while it is executing. You must catch this or return it to be handled higher up (depending on whether it makes sense for the current method to do so). These and similar concurrent exceptions may only start to appear under heavy load in production when contention for threading resources becomes a factor. It is important to use a tool like Raygun that can track and group these sensibly, so you can see how often and when these are occurring as their transient nature can be quite difficult to reproduce locally.

IllegalArgumentException

This is one you should be throwing in your own code, so that at runtime when a method receives invalid input you can throw an appropriately typed exception. Raygun can show instances of these, and as in the null pointer case, you can attach custom data to see the particular invalid arguments that were passed in (for instance, zero as the denominator for a Divide() method). This would be invaluable when developing anything that accepts user input, for instance a web API or service, mobile app, or desktop application.

Get started with Raygun now

Interested in trying professional-grade error tracking? All of these insights and more are available with Raygun, so start your free 30-day trial now, no credit card needed. Happy exception blasting!

Top 4 Java exceptions Raygun can help fix

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.